While it is true that you can run any old cmd command in PS, sometimes you may run into issues due to the syntax of Powershell.
There's a good article about this:
http://blogs.technet.com/b/josebda/archive/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters.aspx
I personally prefer using here-string with Invoke-expression:
This is especially helpful when you run into some heavy quoting issues. I can see your $ sign within double quotes may prompt PS to try interpreting it as a variable which can cause problems.
If you've unfortunately fallen into what some call a "quoting hell", there is one way to get yourself out from it:
one shortcoming of this method is it's not as easy to capture the result or errors if needed. However if all you need is just run the command then this will work for you.
Just from my experience.
EDIT: If you're running PS3 then just add --% anywhere in the line and PS3 will not try to parse the line in PS syntax.
There's a good article about this:
http://blogs.technet.com/b/josebda/archive/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters.aspx
I personally prefer using here-string with Invoke-expression:
$command = @' cmd.exe /C c:\windows\system32\ntbackup.exe backup "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\chameme.bks" /n "1file.bkf1 created 06/09/2013 at 09:36" /d "Set created 06/09/2013 at 09:36" /v:no /r:no /rs:no /hc:off /m normal /j chameme /l:s /f "\\fs1\Exchange Backups$\1file.bkf" '@ Invoke-expression -Command:$command
This is especially helpful when you run into some heavy quoting issues. I can see your $ sign within double quotes may prompt PS to try interpreting it as a variable which can cause problems.
If you've unfortunately fallen into what some call a "quoting hell", there is one way to get yourself out from it:
$batchFileContent = @' @echo off c:\windows\system32\ntbackup.exe backup "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\chameme.bks" /n "1file.bkf1 created 06/09/2013 at 09:36" /d "Set created 06/09/2013 at 09:36" /v:no /r:no /rs:no /hc:off /m normal /j chameme /l:s /f "\\fs1\Exchange Backups$\1file.bkf" '@ $batchFileContent | Out-File -LiteralPath:"$env:TEMP\backup.cmd" -Force Invoke-expression -Command:"$env:TEMP\backup.cmd" Remove-Item -LiteralPath:"$env:TEMP\backup.cmd" -Force
one shortcoming of this method is it's not as easy to capture the result or errors if needed. However if all you need is just run the command then this will work for you.
Just from my experience.
EDIT: If you're running PS3 then just add --% anywhere in the line and PS3 will not try to parse the line in PS syntax.
- Edited by AverageJoeOfToronto Monday, September 09, 2013 5:26 AM additional info
- Proposed as answer by R Jason Morgan Monday, September 09, 2013 1:44 PM
- Marked as answer by Andy QiMicrosoft contingent staff, Moderator Sunday, September 22, 2013 7:09 AM
'컴퓨터관련' 카테고리의 다른 글
powershell escaping quotes, backtick...펌 (0) | 2016.05.08 |
---|---|
powershell quote in quote, double quote...펌 (0) | 2016.05.08 |
스포티지 1.7 실연비 얘기...펌 (0) | 2016.05.04 |
네이버밴드 초대하기...카카오톡...펌 (0) | 2016.05.04 |
[스크랩] 컴퓨터로 휴대폰 원격제어 (0) | 2016.04.30 |