Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Friday, April 16, 2010

Generate New GUID by PowerShell

It's simple and easy to get GUID using PowerShell.
Just type the following line in PowerShell command prompt:
[System.Guid]::NewGuid().toString()
If you need GUID wrapped in curly braces modify the script line to:
"{"+[System.Guid]::NewGuid().toString()+"}"

For me the typical action after getting a GUID is to copy it to the clipboard so the following snippet is my favorite.
$guid="{"+[System.Guid]::NewGuid().toString()+"}"
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$dataObject = New-Object windows.forms.dataobject
$dataObject.SetData([Windows.Forms.DataFormats]::UnicodeText, $true, $guid)
[Windows.Forms.Clipboard]::SetDataObject($dataObject, $true)
write-host The following GUID has been copied to the clipboard: $guid
So once you run the last script you have a new GUID in the clipboard. As for me - that what I call convenient

Friday, April 9, 2010

Hello PowerShell!!

As soon as new Microsoft Products are delivered with PowerShell SnapIns it makes more sense to put a toe into programming it. I have Windows Server 2008 R2 as a main platform for development. On Windows Server 2008 R2 Windows PowerShell ISE isn't running by default. To turn it on, a corresponding feature, called Windows PowerShell ISE should be added in Roles and Features. To do this:
1) Open Windows Start menu.
2) Right click on Computer
3) Select Features
4) Add "Windows Powershell Integrated Script Environment" feature

When ISE is added you could just open Start menu and type "ISE". If you have Windows Vista, Windows 7 or Windows Server 2008 you'll a couple of programs displayed.


Alternatively, you could just select it though Start/Accessories/PowerShell menu

Right click on it and select "Run as an administrator". For some tasks it's not needed, but some just fail without trying to elevate permissions.
When you have ISE opened you'll see a windows separated to 3 areas.

The top part (Script Pane) allows to edit a script and run it at once The middle (Output Pane) shows PowerShell output and the lower one (Command Pane) allows to enter commands interactively, one by one. To make the intro complete we'll run a Hello World like program to be sure that we have really started.
So, copy the following two lines to the Script Pane (top one)

name = Read-Host -Prompt "What is you name?" Write-Host Hello $name! Welcome to PowerShell world
and then press "Run"

you'll see a prompt asking for a name. Enter your name and press ok

Then you'll see that a middle sections contains a prompt welcoming you to the world of PowerShell.

After running a script all variables are stored in the session and you could access them through the immediate window
So if you put
$name
into the Command Pane and press Enter

you'll see what name was entered previously

As any language, PowerShell has much more to learn, but it's a scripting language that worth investing your time if you work on Windows Platform

Saturday, March 13, 2010

An Introduction to Windows PowerShell and IIS 7.0

The following link may be interesting for people who is interested in manageing IIS through powershell scripts
An Introduction to Windows PowerShell and IIS 7.0.