V
V
vkrutik2018-12-06 21:44:48
PowerShell
vkrutik, 2018-12-06 21:44:48

Powershell how to compose a command correctly?

The task to transfer data to the
PS site It is launched by such a command, where %s is data
PowerShell.exe C:\script.ps1 %s
The command itself:

$id = $args[0]
invoke-RestMethod -Uri "http://site.com/$id" -Method GET

There are two questions:
1) Is the powershell script correctly compiled for this case? (if not, please provide a more correct version)
2) The above construction works, it transmits data, but adds such characters to the end ​ , why and how to remove it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2018-12-07
@azarij

no, it doesn't add anything. tried like this:
$id = $args[0]
$id
" https://www.google.com/search?q=$id "
invoke-RestMethod -Uri " https://www.google.com/search?q =$id " -Method GET
what I pass to the script from the command line - is searched in Google as it was passed without any changes.
how do you run the script?
which version turned - $psversiontable?
Is the site supposed to add something? if you just output the URL that you pass to the restmethod to the console - is it already with the addition or already without it?
have you tried it on another machine?
have you tried it on another site?
Is $id something numeric or text?
but about right ... scripts of such length and complexity do not operate with the concepts of right or wrong. instead, they have another property that is important - whether it works or not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question