Author Posts

June 16, 2016 at 8:13 am

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

June 16, 2016 at 12:17 pm

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

June 16, 2016 at 2:48 pm

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.