Tuesday, April 3, 2012

Download a file from an ftp server in powershell


Define the file you’d like to download and where to save:

$ftpfile = "ftp://ftp.adobe.com/pub/adobe/reader/win/10.x/10.1.2/en_US/AdbeRdr1012_en_US.exe"
$localfile = "C:\temp\AdbeRdr1012_en_US.exe"

Create new-objects. Click on the corresponding links to get information about “system.net.webclient” and “system.uri

$ftpclient = New-Object system.Net.WebClient
$uri = New-Object System.Uri($ftpfile)

And finally, download the file:

$ftpclient.DownloadFile($uri,$localfile)

Monday, April 2, 2012

Create a message box in powershell


Today I’d like to show how to create a message box in a very simple way:

What we need is some text, a title, the definition of our buttons and an icon for our window.

$text = "This is just a test"
$title = "Testbox"
$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK
$Icon = [System.Windows.Forms.MessageBoxIcon]::Information

So now we got everything we need to pop this window up and we do it with this little command:

[System.Windows.Forms.MessageBox]::Show($text,$title,$Buttons,$Icon)

And that’s the result: