New-PSDrive Long Root Name

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

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

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.