Saturday, November 22, 2008

error handeling

Trap [Exception] { “In PowerShell”

Catch-Error.ps1

 

#Requires -Version 2
# Show-TryCatchFinally.ps1
# Demonstrates try/catch/finally in V2
# First, try something that will work
Try {
$I=1
}
Catch {"Caught a problem in try 1"
}
Finally {
"All done with 1st try"
}

# Now try something that fails
$one=1
#$zero=0
Try { $one/$zero}
Catch {"Caught a problem in try 2"}
 

 


Default Error Handling
Error handling in PowerShell scripts
Lunch Lesson: Error Handling in PowerShell

Methods for handling errors in PowerShell can range from simple to complex

for each

  In PowerShell, foreach is both a statement and an alias to the ForEach-Object cmdlet. 

While you might think that both of these examples do exactly the same thing, they do not. 

Powershell tutorial 8 part 1

PowerShell tutorial 8 part 2

Essential PowerShell: Understanding foreach

 

 

Wednesday, November 12, 2008

Powershell and the VI Toolkit!

new, 12-19-08 PowerGUI VMware PowerPack has lots of great features, including the ability to manage your ESX Hosts and VMs, as well as doing bulk operations. In my opinion, PowerGUI's best feature is that as you interact with PowerGUI, it generates PowerShell code as you go. You can take this code and re-run it later or you can parameterize it and turn it into a script. This is especially great if you're not a hard-core scripter, or if you aren't very familiar with PowerShell.


VMware in PowerGUI


Powershell and the VI Toolkit! plus
Project Description
The VI Toolkit for Windows Community Extensions is a PowerShell module designed to work with the VI Toolkit for Windows (http://vmware.com/go/powershell).

Project Goals
This project aims to help make managing VMware products with PowerShell easy and really powerful. Our current VI Toolkit for Windows contains 125 cmdlets that makes life a lot easier for people who manage VMware ESX and VMware VirtualCenter. With this project we plan to build on that by providing libraries of really useful stuff based on the ideas we see in our VMware Community as well as plenty of ideas of our own

For script nodes to work you would need to either:


  • start PowerGUI as VI Client plugin, or
  • add Connect-VI-Server to your PowerShell profile, or
  • add the -Server $global:VIServer to your scripts.


Quick VI Toolkit One-liners

 Setting of advanced options with the VI Toolkit
 Track Datastore Free Space
 VMware Stats Oneliner
 How many VMs in each LAN?
 VMware Server info
 Changing your VMware license server
  top-twenty volumes on your virtual servers with the least free disk space

Some advice on creating Powershell scripts

Some Advice on Creating Powershell Scripts (Part 2)

PrimalForms

get the free PrimalForms tool
 PrimalScript Packaged PrimalForm PowerShell
 Creating a PowerShell GUI with PrimalForms

PowerShell cmdlets for AD

PowerShell cmdlets for AD
 Andrei published on PowerGUI.org a bunch of how-to’s to Active Directory management with PowerShell:

 How can you set any arbitrary AD attribute with PowerShell


Creating a PowerShell GUI with PrimalForms