none
New-PSDrive suddenly not working RRS feed

  • Question

  • I have a script that maps several drives to automate the process of grabbing files from various locations.  Below is a section of the script that is causing issues.

    #Setting XXXXXXXX network directory
    Write-Host "Provide credentials to connect to XXXXXXX.  Domain should be XX."
    $creds=Get-Credential -Credential gsc\
    pause
    $DriveMapped=Get-PSDrive -Name T -ErrorAction SilentlyContinue
    if ($DriveMapped.Name -eq "T") {}
    Else {
    New-PSDrive -Name T -PSProvider FileSystem -Root \\XXXXXXXX\XXXXXXXX\Store\ -Credential $creds -Persist
    }
    $XXXXXXXXBaseDirectory=Get-ChildItem -Path \\XXXXXXX\XXXXXXX\Store\Emerald | select FullName | Out-GridView -OutputMode Single -Title "Select the Emerald path you'd like to copy from."
    [System.Collections.ArrayList]$MicroServices=Get-ChildItem -Path \\XXXXXXXXX\XXXXXXXX\Store\XXXXXXX | Out-GridView -OutputMode Multiple -Title "Select all the MicroServices paths you'd like to copy from."

    This section of the script did work and suddenly stopped, providing the following error:

    writeErrorStream      : True
    Exception             : System.ComponentModel.Win32Exception (0x80004005): The network name cannot be found
    TargetObject          : T
    CategoryInfo          : InvalidOperation: (T:PSDriveInfo) [New-PSDrive], Win32Exception
    FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
    ErrorDetails          : 
    InvocationInfo        : System.Management.Automation.InvocationInfo
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo : {0, 1}
    PSMessageDetails      : 

    I am using the IP of the FTP server to attach, if I browse to this address it works using the same credentials provided for this script.  Also later on in the script I map to another location that uses the same credentials that also works.

    Looking for guidance on why this is not working suddenly.

    Thursday, August 30, 2018 6:09 PM

Answers

  • For some reason placing quotes around the -Root string resolved the issue.
    Friday, August 31, 2018 5:14 PM

All replies

  • Then name you are trying to access is not there. 

    This name "\\XXXXXXXX\XXXXXXXX\Store\"

    Be sure it is correctly shared.


    \_(ツ)_/

    Thursday, August 30, 2018 7:11 PM
  • Then name you are trying to access is not there. 

    This name "\\XXXXXXXX\XXXXXXXX\Store\"

    Be sure it is correctly shared.


    \_(ツ)_/

    As stated above the location is there, I can browse to the same path, using the same credentials, using explorer.  I can also use the same credentials to access other shares so the credentials are not the issue and neither is the share actually existing.
    Friday, August 31, 2018 1:22 PM
  • For some reason placing quotes around the -Root string resolved the issue.
    Friday, August 31, 2018 5:14 PM
  • For some reason placing quotes around the -Root string resolved the issue.

    We could not have helped and the path exisitence was the issue as you have just proven.  This is likely due to the structure of the path string.  If you are using variables in the path then it will require quotes.  It there are spaces and other characters then it will require quotes.


    \_(ツ)_/

    Friday, August 31, 2018 5:44 PM