Search code examples
powershellcmdinvoke-webrequest

Powershell script run in Command Prompt


I would like to know how to implement Powershell script run into Command Line successfully?

Actually, I tried to run it and show an error message like that:

Basic : The term 'Basic' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.

enter image description here Anyone can help me? Thanks.

Powershell Script

Invoke-WebRequest -Uri "http://XX.XX.XX.XXX/123.cgi" -Headers @{ "Authorization"="Basic WjVfb3AljjFkjZluOm7hAE9pbjQx"} -OutFile '123.csv'

Solution

  • Guessing what your question really is, perhaps your preferred one these will suffice:

    %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NoLogo -Command "Invoke-WebRequest -Uri \"http://XX.XX.XX.XXX/123.cgi\" -Headers @{ \"Authorization\" = \"Basic WjVfb3AljjFkjZluOm7hAE9pbjQx\" } -OutFile \"123.csv"\"
    
    %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NoLogo -Command "Invoke-WebRequest -Uri 'http://XX.XX.XX.XXX/123.cgi' -Headers @{ 'Authorization' = 'Basic WjVfb3AljjFkjZluOm7hAE9pbjQx' } -OutFile '123.csv'"
    

    Please note that this, as did yours, does not provide a full path for the CSV file for output, and will therefore use whatever your current working directory is.