Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Dealing with spaces in paths when using a command in cmd.exe

$
0
0

Good Morning,

I am having slight issues with a snippet I have written - it does not deal with spaces very well in the file-name:

I have moved all of the folders that do not have spaces in but I cannot do the same for the ones that do.

 $ObsoleteFolders = Import-Csv C:\path\to\csv\ObsoleteFolderList.csv


ForEach ($Folder in $ObsoleteFolders)

{

    $Name = $Folder.ObseleteFolderList

    $Source = "'\\server\users$\$Name'"

    cmd.exe /C  "move $Source  \\server\users$\UnusedHomeDirs"

}

If there is a space in the $Name variable I get the following output:

cmd.exe : The syntax of the command is incorrect.

Thanks very any help you can provide


Viewing all articles
Browse latest Browse all 6937

Trending Articles