Category: PowerShell

Cmdlet verb names

By , 31 august, 2008 22:36

Last week I worked with a PowerShell script where I did a big blunder!   I had created a function with the name “Start” and I did not find the reason of why my script failed before at least one hour. Start is one of the PowerShell reserved verbs so stay away from them in your function names or variables!

List of reserved PowerShell verbs at Microsoft: http://msdn.microsoft.com/en-us/library/ms714428.aspx

Or you can of course list the verbs with PowerShell:
$verbs = [System.Reflection.Assembly]::LoadWithPartialName(«System.Management.Automation»)
$verbs.GetTypes() | where {$_.Name -match «Verbs»} | foreach {$_.GetFields() | foreach {$_.Name}} | sort

Post to Twitter Post to Facebook Post to LinkedIn

VMware have now released the full version of VMware Infrastructure Toolkit 1.0

By , 19 august, 2008 10:05

With the VI toolkit you can automate standard management tasks like cloning, moving, starting or stopping virtual machines and hosts true PowerShell. VI Toolkit takses advantage of the exisiting VMware Infrastructure SDK and translate it into a PowerShell interface.

http://www.vmware.com/sdk/vitk_win/index.html?src=EM_0803_VMW_OTHER_VITOOLKIT_DOWNLOAD

After you have installed PowerShell and VI Toolkit on your computer, you have to add the VI Toolkit powershell snapin:

# List the snappins you allready have installed:
PS C:\> get-pssnapin

# List registered snapins:
PS C:\> Get-PSSnapin -Registered

# Add the VMware.VimAutomation.Core snappin:
PS C:\> Add-PSSnapin VMware.VimAutomation.Core

# Connect to your Virtual Center server:
PS C:\> Get-VIServer x.x.x.x -User admin -Password xxxxxxx

# List virtual maschines who are powered on:
PS C:\> get-vm | Where-Object {$_.powerstate -eq ‘PoweredOn’}

Post to Twitter Post to Facebook Post to LinkedIn

Great PowerShell book

By , 13 august, 2008 09:02

For those of you who wish to learn or read more about PowerShell I will  recommend the book PowerShell in Action by Bruce Payette. Bruce Payette is  one of the co-designers of the PowerShell language. The book contents great examples and is easy readability.

PowerShell in Action

  

 

http://manning.com/payette/

 

 

 

Post to Twitter Post to Facebook Post to LinkedIn

Long PowerShell statements

By , 11 august, 2008 20:36

PowerShell statements can be large, and it’s not always practial to enter it on a single line in the console or in a script. In PowerShell, as wel as in most other programming lanuages or consoles it is posible to write statements over several lines.

When the console determines a line is incomplete, powershell continues to the next line processing the statement. For example, where the first line in a statement ends with the pipe operator, as in:

Long statement example:

18# Get-Process | Where {$_.ProcessName -eq ‘msiexec’} | Format-table ID, CPU, Name
Id CPU Name
– — —-
4808 0,046875 msiexec

Same statemen over three lines:

19# Get-Process |
>> Where {$_.ProcessName -eq ‘msiexec’} |
>> Format-table ID, CPU, Name
>>
Id CPU Name
– — —-
4808 0,046875 msiexec

In a PS1 script you can use the ` tag:

$excel = New-Object -comobject `
excel.application

Post to Twitter Post to Facebook Post to LinkedIn

Panorama Theme by Themocracy