Possible Duplicate:
Get $webclient.downloadstring to write to text file in Powershell
Powershell http post with .cer for auth
I have an SMS system that provides me the ability to send an SMS from an HTTP GET request:
http://smsserver/SNSManager/msgSend.jsp?uid&to=smartsms:*+001XXXXXX&msg="text of the message"&encoding=windows-1255
I want to enter the details to the text from PowerShell and just surf to this URL. How can I do it?
We can use PowerShell to copy a file from one location to another with the Copy-Item cmdlet. The location can be another local folder or a remote computer. Besides files, we can also copy complete folders with subfolders and content. And it's even possible to filter the files that we copy.
Turns out the answer is fairly straight forward, wrap the command in a loop forever. This'll allow you to Ctrl-C out of it, and it'll keep repeating even after your command completes or otherwise exits the first time.
The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.
Get-Service gets all the services on the computer and sends the objects down the pipeline. The Where-Object cmdlet, selects only the services with a Status property that equals Running . Status is only one property of service objects. To see all of the properties, type Get-Service | Get-Member .
In PowerShell v3, have a look at the Invoke-WebRequest and Invoke-RestMethod e.g.:
$msg = Read-Host -Prompt "Enter message" $encmsg = [System.Web.HttpUtility]::UrlEncode($msg) Invoke-WebRequest -Uri "http://smsserver/SNSManager/msgSend.jsp?uid&to=smartsms:*+001XXXXXX&msg=$encmsg&encoding=windows-1255"
Downloading Wget is not necessary; the .NET Framework has web client classes built in.
$wc = New-Object system.Net.WebClient; $sms = Read-Host "Enter SMS text"; $sms = [System.Web.HttpUtility]::UrlEncode($sms); $smsResult = $wc.downloadString("http://smsserver/SNSManager/msgSend.jsp?uid&to=smartsms:*+001XXXXXX&msg=$sms&encoding=windows-1255")
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