Powershell with Literal Path


When folder name has [], you can escape them with two back tick “ to escape them to create a file by using the path with special characters.

  
  
 
 
 
New-Item  –Path "c:temp\``[Profile Backup``]\$(Get-Date -Format yyyy_MM_dd)\" -Name "Installed_Programs1.txt" -ItemType File -Force

New-Item  –Path "c:temp\``[Profile Backup``]\2017_03_17\" -Name "Installed_Programs1.txt" -ItemType File -Force
 
 
 ##create the folder(don't need escape), then create the file
md -Path "c:temp\[Profile Backup]\$(Get-Date -Format yyyy_MM_dd)" -Force
New-Item  –Path "c:temp\``[Profile Backup``]\$(Get-Date -Format yyyy_MM_dd)\" -Name "Installed_Programs1.txt" -ItemType File -Force

 

https://technet.microsoft.com/en-us/library/ff730956.aspx

https://social.technet.microsoft.com/Forums/windows/en-US/27c62029-49c2-4170-864a-9c3781737a64/newitem-not-creating-file-why-not?forum=winserverpowershell

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s