Episode 1 of the NetPoint PowerShell Commands

Back in March I wrote a blog about the NetPoint PowerShell Commands, which are now available in NetPoint 2.5. These commands can be used to query your network inventory from PowerShell, so you can easily automate those repetitive system and asset management tasks.

Within the upcoming week or two, I plan on posting a set of videos that will show how these cmdlets can be used to automate some typical IT scenarios.  This first episode gives a brief introduction of the NetPoint PowerShell Commands.  We also walk-through a scenario that involves getting a list of the programs installed on an arbitrary machine in just one line of script.

In the next episode, we’ll look at generating custom network inventory reports right from PowerShell, so stay tuned!

Update: PowerShell SnapIn for XenServer Snapshots 1.01

I just released a update of the PowerShell SnapIn for XenServer Snapshots, which can be found here. This version contains a NoStart switch on the Restore-VM cmdlet. By default Restore-VM will start the virtual machine after its been reverted. You can now specify the NoStart switch if you don’t want it to be started. Here’s a brief example:

Restore-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup -NoStart

I’m always interested in hearing feedback, so feel free to post any questions or comments you have.

P.S. If you’re a XenApp customer, Citrix Receiver for the iPhone (aka the XenApp client for the iPhone) is now available in the AppStore. Chris Fleck has posted a demo if it here. Unfortunately, I haven’t been able to try this out as I don’t (yet) have one of these snazzy phones.

PowerShell Cmdlets for Network Inventory

This past week I spent a few evenings on my balcony coding the final bits of Project Full Moon.  Full Moon is a set of PowerShell Cmdlets for NetPoint, which are targeted at helping IT Pros automate repetitive system and asset management tasks.

In this post I’ll show how you can use these commands to make your life a bit easier.  Here are some scenarios I’ll walk through:

  • You’re interested in getting a list of the apps installed on a certain system
  • Some of your Dell workstations are having issues with their NVIDIA graphics cards.  You need to apply a driver update to all of these systems.
  • It’s that time of the year to buy new hardware.  You need to determine if there are any systems that need a hard drive upgrade.
  • There’s a new virus in the wild.  You need to ensure all of your systems are protected with up to date virus definitions.

So let’s get started!  First let’s add the NetPoint PowerShell SnapIn and get a list of our network inventory cmdlets:

Add-PSSnapin Neutex*
Get-Command -PSSnapin Neutex*

PowerShell will list the 20 cmdlets available to us:

  • Get-NetAntiVirus
  • Get-NetBIOS
  • Get-NetCDROMDrive
  • Get-NetDiskDrive
  • Get-NetFirewall
  • Get-NetFloppyDrive
  • Get-NetLogicalDisk
  • Get-NetMemory
  • Get-NetModem
  • Get-NetMonitor
  • Get-NetNetworkAdapter
  • Get-NetOperatingSystem
  • Get-NetPatch
  • Get-NetPrinter
  • Get-NetProcessor
  • Get-NetProgram
  • Get-NetService
  • Get-NetSoundDevice
  • Get-NetSystem
  • Get-NetVideoController

Now we're ready to tackle our scenarios.

You're interested in getting a list of the apps installed on a certain system

Get-NetProgram can be used to retrieve a set of programs.  Running this command by itself will return all programs that have been installed on our network (even those that have been uninstalled).  Like all of our other network inventory commands, it also accepts a set of parameters (app name, publisher, how often it's used, etc.) that can be used to filter its results.  Here is the script that will get us the results we want:

Get-NetProgram -System maui -Uninstalled $False | % { $_.DisplayName } | sort -unique

This command starts out by retrieving all of the apps installed on the system named maui.  By default, we’ll get a whole set of information about each app, but we only want the app names so we’ll pipe this into % { $_.DisplayName } and sort it so we can easily get an idea of the installed apps.

Some of your Dell workstations are having issues with their NVIDIA graphics cards.  You need to apply a driver update to all of these systems.

The data we need to target for this scenario is spread across two domains: video controller (NVIDIA graphics cards) and system (Dell workstations).  We’ll use Get-VideoController in conjunction with Get-System to get the job done:

Get-NetVideoController -Name nvidia* -Uninstalled $False | Get-NetSystem -Manufacturer dell* | % { $_.ComputerSystemName } | sort -unique

Here we’re getting a list of all installed graphics cards whose name starts with NVIDIA.  We then pipe this to Get-System with the Manufacturer parameter set.  This will return all Dell systems that contain an NVIDIA graphics cards.  The last two portions of this script will cause only the system names to be returned in alphabetical order.

You could use this output with the WMI cmdlets to install the driver update.

It’s that time of the year to buy new hardware.  You need to determine if there are any systems that need a hard drive upgrade.

In this scenario, we’re interested in using the Get-NetLogicalDisk cmdlet as follows:

Get-NetLogicalDisk -DriveType "Local Disk" | where { $_.FreeSpace / $_.Size -lt .10 } | % { $_.ComputerSystemName }

The first portion of this script will get all partitions that are stored on hard disks (versus CDs, floppies, etc.).  We proceed by using PowerShell’s where command to only get partitions that have less than 10% of free space and we pipe this to % { $_.ComputerSystemName } to only get a list of the system names.

There’s a new virus in the wild.  You need to ensure all of your systems are protected with up to date virus definitions.

This scenario is a little more complex than the previous ones, however we can still solve it in two lines of PowerShell.

$i = Get-NetAntiVirus -Uninstalled $False -UptoDate $True | % { $_.ComputerSystemName } | sort -unique
Get-NetSystem | where {$i -notcontains $_.ComputerSystemName} | % { $_.ComputerSystemName } | sort -unique

The first line will get us names of all the systems that have an antivirus client with up to date virus definitions.  The second line will subtract this list from all of the systems on our network using the where command, which leaves us with the unprotected systems.  The WMI cmdlets could also be used here to install an updated antivirus client on these systems.

That pretty much sums up some of the basic scenarios you can address with NetPoint’s PowerShell Cmdlets.  There is some documentation work that still needs to be sorted out, however you can expect to see the final bits online in a couple of weeks.  In the meantime if you don’t already have a copy of NetPoint, you can get the free Express Edition here.

XenServer 5.0 SDKs Released to Web

Incase you haven’t heard, the XenServer 5.0 SDKs have been released. Here’s a short summary of them:

  • New XenServerPSSnapIn: This is the PowerShell snap-in for XenServer, which is a one-to-one mapping of the existing XenServer API. It should be noted that the functionality in XenServerSnapshotPSSnapIn can be duplicated with this, however it will take many lines of scripting. You can use both snap-ins together if you’d like to manage your XenServers and take snapshots via PowerShell.
  • Updated XenServer.NET: The XenServer SDK for .NET
  • Updated XenServerJava: The XenServer SDK for Java
  • Updated libxenserver: The XenServer SDK for C
  • Updated XenAPI.py: The XenServer Python module

The SDKs can be downloaded from Citrix Community. Enjoy!

Hot Off the Compiler: PowerShell SnapIn for XenServer Snapshots

As a follow-up to my Snapshotting with the XenServer 5.0 SDK post, I’ve written a PowerShell snapin that will allow you to take and revert snapshots with XenServer. You can download the source code and binaries here. You must have the .NET Framework 3.5 installed before you can use it. To install the snapin you will need to run the following command after you’ve downloaded and extracted the ZIP file:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /i XenServerSnapshotPSSnapIn.dll

Then you can open up your PowerShell console and enter the following to take a snapshot of your virtual machine named Bluemoon, which by the way is my favorite beer!

Add-PSSnapin XenServerSnapshot*
Checkpoint-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup

If you decide you’d like to revert to this snapshot you can do this:

Restore-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup

And before I leave the office for the night, here are a few things to note:

  • The cmdlets return true if they were able to execute successfully, otherwise they return false.
  • Virtual machine names are case-sensitive.
  • PowerShell must be installed to compile the source. XenAPI.net is included with the download.
  • I’ve made a few tweaks to this code from the original version.

Added 09-March-2009: The snapshot feature in XenServer requires a VHD-on-EXT3 storage repository.  To change the default repository to EXT3, please see http://support.citrix.com/article/ctx116324.  Alternatively, the following script can be used:

dev=`cat /etc/xensource-inventory | grep DEFAULT_SR_PHYSDEVS | cut -d ‘=’ -f2 | grep -o -E “[^'].*[^']“`

sr_uuid=`xe sr-list type=lvm | grep uuid | cut -d ‘:’ -f2 | cut -c 2-`

pbd_uuid=`xe pbd-list sr-uuid=$sr_uuid | grep -E ‘^uuid.*’ | cut -d ‘:’ -f2 | cut -c 2-`

inst_uuid=`cat /etc/xensource-inventory | grep INSTALLATION_UUID | cut -d ‘=’ -f2 | grep -o -E “[^'].*[^']“`

xe pbd-unplug uuid=$pbd_uuid

xe sr-destroy uuid=$sr_uuid

new_sr_uuid=`xe sr-create content-type=”local SR” host-uuid=$inst_uuid type=ext device-config-device=$dev shared=false name-label=”Local File SR”`

pool_id=`xe pool-list | grep uuid | cut -d ‘:’ -f2 | cut -c 2-`

xe pool-param-set default-SR=$new_sr_uuid uuid=$pool_id

xe pool-param-set suspend-image-SR=$new_sr_uuid uuid=$pool_id

#echo $dev
#echo $sr_uuid
#echo $pbd_uuid
#echo $inst_uuid
#echo $new_sr_uuid
#echo $pool_id

Feel free to post a comment here if you have any feedback. Enjoy!

Follow

Get every new post delivered to your Inbox.