locked
Downloading multiple files from SharePoint RRS feed

  • Question

  • Here is a part of the code I'm writing to download various files from various directories:

    #Get Project Files from SharePoint
     #Gathering the location of the PM SpreadSheet and Destination folder
    $spPath = "\\MySharePointSite.com\Customers"
    $Spread = "$spPath\Customer"
    $Sheets = "$ScriptPath\Customer\PMInfo"

     #Gathering the location of the Card Formats and Destination folder
    $Card = "$spPath\Customer\Forms"
    $Forms = "$ScriptPath\Customer\Forms"

     #Gathering the location of the Tracklayouts and Destination folder
    $Track = "$spPath\$OPTY\Customer\TrackRecords"
    $Records = "$ScriptPath\$CUST\TrackRecords"

    #Get User Information
    $user = Read-Host "Enter your username"
    $username = "$user@corporate"
    $password = Read-Host "Enter your password" -AsSecureString

    #Get Integration Documents from SharePoint
    $credential = New-Object System.Management.Automation.PSCredential($UserName, $Password)
    New-PSDrive -Credential $credential -Name "A" -PSProvider "FileSystem" -Root "$spPath"
    net use $spPath #$password /USER:$user@MyCompany

    #Get PMDeliverables file objects recursively
    Get-ChildItem -Path "$Spread" | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $Sheets
    #Get all cardFormats file objects recursively
    Get-ChildItem -Path "$Card" | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $Forms
    #Get tracklayouts file objects recursively
    Get-ChildItem -Path "$Track" | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $Records
    net use $spPath /delete
    Remove-PSDrive -Name "A" -PSProvider "FileSystem" -Root "$spPath"

    Write-Host "Customer $PSCust created, you can exit now."

    _______________________________________________________________________________________________

    I get the error when trying to run the script:

    New-PSDrive : The network name cannot be found
    At C:\NewCustomer\NewCustomerFolder_Update.ps1:83 char:1
    + New-PSDrive -Credential $credential -Name "A" -PSProvider "FileSystem" -Root "$s ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (A:PSDriveInfo) [New-PSDrive], Win32Exception
        + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
     
    net : System error 67 has occurred.
    At C:\NewCustomer\NewCustomerFolder_Update.ps1:84 char:1
    + net use $spPath #$password /USER:$user@corporate
    + ~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (System error 67 has occurred.:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
     
    The network name cannot be found.
    Get-ChildItem : Cannot find path '\\MySharePointSite.com\Customers\Customer\NewCustomer' because it does not exist.
    At C:\NewCustomer\NewCustomerFolder_Update.ps1:87 char:1
    + Get-ChildItem -Path "$Spread" | Where-Object { $_.name -like 'MS*' } | Copy-Item ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (\\MySharePointSite.com\Customers\Customer\NewCustomer:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    Get-ChildItem : Cannot find path '\\MySharePointSite.com\Customers\Customer\NewCustomer' because it
    does not exist.
    At C:\NewCustomer\NewCustomerFolder_Update.ps1:89 char:1
    + Get-ChildItem -Path "$Card" | Where-Object { $_.name -like 'MS*' } | Copy-Item - ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (\\MySharePointSite.com\Customers\Customer\NewCustomer\CardForms:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    Get-ChildItem : Cannot find path '\\MySharePointSite.com\Customers\Customer\NewCustomer\TrackRecords' because it
    does not exist.
    At C:\NewCustomer\NewCustomerFolder_Update.ps1:91 char:1
    + Get-ChildItem -Path "$Track" | Where-Object { $_.name -like 'MS*' } | Copy-Item  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (\\MySharePointSite.com\Customers\Customer\NewCustomer\TrackRecords:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    net : The network connection could not be found.
    At C:\NewCustomer\NewCustomerFolder_Update.ps1:92 char:1
    + net use $spPath /delete
    + ~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (The network con...d not be found.:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
     
    More help is available by typing NET HELPMSG 2250.

    _______________________________________________________________________________________________

    How do I get it to quit putting in "NewCustomer" into the path?

    Thanks,

    UnderDog


    Richard

    Wednesday, September 28, 2016 6:12 PM

Answers

All replies