New-PSDrive Long Root Name

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Aaron Hardy Aaron Hardy 3 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43544
    Profile photo of Adrian LLoyd
    Adrian LLoyd
    Participant

    I am trying to map a drive using New-PSDrive.

    I am using the code below. It errors saying "New-PSDrive : The network resource type is not correct"
    I think the error is caused by $Script breaking onto a new line mid way through the path. New-PSDrive does not seem to look to the next line. I have tried re-ordering the parameters with no affect.

    The code works if I resolve $Script, copy the line into the console and delete the line breaks. Has anyone seen this before / can help? The file path does not include any special characters that should trigger a line break.

     
    $FolderToMap = [LONG NAME INCLUDING SPACES]
    $Script="New-PSDrive -Persist -Name A -Root `"$FolderToMap`" -PSProvider FileSystem -scope Global"                                                      
    Invoke-Expression $Script
    
    #43550
    Profile photo of Jim Topp
    Jim Topp
    Participant

    You're using backticks that you may think are single quotes. Change those to single quotes and see what happens.

    #43607
    Profile photo of Aaron Hardy
    Aaron Hardy
    Participant

    Are you using single quotes in $FolderToMap? It's not specified so just confirming. If not, use:

    $FolderToMap = 'path including spaces'

    Or if the path has variables in it, use double quotes instead of single quotes. Remove backticks from the -Root parameter value.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.