New-PSDrive Long Root Name

Welcome Forums General PowerShell Q&A New-PSDrive Long Root Name

This topic contains 2 replies, has 3 voices, and was last updated by

3 years, 1 month ago.

  • Author
  • #43544

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    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.

    $Script="New-PSDrive -Persist -Name A -Root `"$FolderToMap`" -PSProvider FileSystem -scope Global"                                                      
    Invoke-Expression $Script
  • #43550

    Topics: 1
    Replies: 8
    Points: 46
    Rank: Member

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

  • #43607

    Topics: 10
    Replies: 43
    Points: 48
    Rank: Member

    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.

The topic ‘New-PSDrive Long Root Name’ is closed to new replies.