I have a some code in PowerShell and I need to use it in cmd.exe
I am using this command in cmd.exe
powershell -command "command"
But it gives me this error
At line:1 char:72
+ ... nt D:\15.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace REG_SZ, ...
+ ~
You must provide a value expression following the '-replace' operator.
At line:1 char:73
+ ... 5.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace REG_SZ, } | F ...
+ ~~~~~~
Unexpected token 'REG_SZ' in expression or statement.
At line:1 char:79
+ ... .txt -TotalCount 3)[-1] | Foreach-object {$_ -replace REG_SZ, } | Fo ...
+ ~
Missing argument in parameter list.
At line:1 char:113
+ ... -object {$_ -replace REG_SZ, } | Foreach-object {$_ -replace Gmail, ...
+ ~
You must provide a value expression following the '-replace' operator.
At line:1 char:114
+ ... t {$_ -replace REG_SZ, } | Foreach-object {$_ -replace Gmail, } | s ...
+ ~~~~~
Unexpected token 'Gmail' in expression or statement.
At line:1 char:119
+ ... {$_ -replace REG_SZ, } | Foreach-object {$_ -replace Gmail, } | se ...
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
My command is :
powershell -command "(Get-Content D:\15.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace "REG_SZ", " "} | Foreach-object {$_ -replace "Gmail", " "} | set-content D:\15.txt"
You can't use doublequotes to wrap the command and inside the command itself. Cmd.exe/Powershell.exe
will end the command at the next double quote which is at "REG_SZ"
in this example. Try using single quotes inside the command:
powershell -command "(Get-Content D:\15.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace 'REG_SZ', ' '} | Foreach-object {$_ -replace 'Gmail', ' '} | set-content D:\15.txt"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With