I use this script to get the results of a url:
@Echo off
For /f "delims=" %%A in (
'powershell -NonI -NoP -C "(Invoke-Webrequest "%~1").content"'
) Do set Line=%%A
I can call it in a command prompt window like this:
WebResponse.cmd "http://websiteremoved.com/teststat.php?username^=%friend1%"
I need to use the caret (^) to cancel out the Equal sign. However when I run that same line of code in my batch file it does not work. According to the test, %~1 is set to "http://websiteremoved.com/teststat.php?username^=Lukaka" but the powershell portion returns this:
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'Lukaka'. [] http://websiteremoved.com/teststat.php?username^=Lukaka
At line:1 char:2 [] http://websiteremoved.com/teststat.php?username^=Lukaka
+ (Invoke-Webrequest http://websiteremoved.com/teststat.p ... [] http://websiteremoved.com/teststat.php?username^=Lukaka
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [] http://websiteremoved.com/teststat.php?username^=Lukaka
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException [] http://websiteremoved.com/teststat.php?username^=Lukaka
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand [] http://websiteremoved.com/teststat.php?username^=Lukaka
Any ideas as to why it is doing this? Thanks a bunch!
cmd.exeat all? Just run the command you want to run directly from the PowerShell prompt.cmd.exe 0.4MBcompared toPowerShell 32MB. (80 times more memory required just to have powershell open) Of course if you have 4G free -- who cares...powershell.exejust to run one command is (to put it mildly) quite inefficient. If you need PowerShell, then use it and leave it open. (Then you're not inefficiently spinning up new copies, because it's already open.)