Skip to Content

Blogs

VMware get-lunpathsetting.ps1

Recently had a need to validate the configured LUN path settings in some of our VMware environments. The prospect of checking them through the VIClient GUI was less then appealing as was checking via command line on each VMhost. So I used VMware's new PowerCLI PowerShell plugin to automate the information gathering. After I did this, my co-worker found a script to set preferences by odd/even Set HBA Preference

We have multiple environments so I tried to make the settings as generic as possible. I added date/time and VIServer to the file name so that it wouldn't get over written if you were running it before and after a configuration change or against different environments.

PowerShell - Quickly getting user logon name

To resolve an issue, a co-worker requested a list of user IDs of the affected employees. The customer just sent a list of people (first name, last name) with no user logon IDs. Using ADUC to look them all up (it was a long list) would have taken a bit of time and rather then try and have the customer revisit everyone I grabbed the lists and ran it through the command line. I had PowerShell launched and didn't want to bother with launching explorer and navigating to the directory (also, as much PowerShell as possible and practical is the game we are playing)

You will need Microsoft's PowerShell and Quests Active Directory tools installed.

Here are the steps...

PowerShell - Enumerating groups to Excel

A friend had a semi-regular request for the members of a long list of distribution groups (70-80). I hacked together something that dumped everthing to a big text file which he then had to convert to an Excel spreadsheet. Not an optimal solution for automation. I thought this was an excellent time to learn how to put data in Excel.

The script as written takes input from a text file of the group (Distribution lists, but any group would work) but you could change that to a query easily enough.

Introduction to PowerShell slides

I recently did an 'Introduction to PowerShell' presentation for some of my co-workers. The idea was to help them expose the them to the various elements of PowerShell and why they should start learning with it now.

The demo is geared to our environment but I think the presentation is basic enough to be useful for others. We have a decent sized VMware environment, which was really my starting point and hook for some co-workers in using PowerShell. For user management we leverage the Quest Active Directory tools.

I used Jaykul's mod of the Start-Demo script. I had to temporarily use the Set-ExecutionPolicy Unrestricted to make it run. I really need to get a better handle on the security policy and start signing my stuff, even if it is only using a locally generated certificate.

I also included a script I wrote to generate a space utilization report. This was on the lines of saving future output in an array and then leveraging PowerShell output tools.

Enjoy. Feedback welcome.

PowerShell Function Get-DriveSpace

Part of what I do entails checking our management/alerting server. On occasion there are alerts that the responsible engineer perhaps failed to clear. One such is 'low disk space'. Rather then just clear those alerts, I generally check them manually to see if I need to bring them to the attention of the responsible engineer.

It occurred to me that manually mapping the drive could be replaced with a nice little PowerShell function.

A little searching, swiping examples and modifying to fit my needs and done. I have added this function to my PowerShell profile.

# Function to get and calculate drives and free space
# Defaults to localhost if no following name is entered
function Get-DriveSpace([string]$SystemName = "localhost") {
$driveinfo = get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer $SystemName
$driveinfo | select deviceid, `
  @{Name="FreeSpace";Expression={($_.freespace/1GB).tostring("0.00")}}, `
  @{Name="DriveSize";Expression={($_.size/1GB).tostring("0.00")}}, `
  @{Name="Percentfree";Expression={((($_.freespace/1GB)/($_.size/1GB))*100).tostring("0.00")}}
}

There are a few servers that use volume mount points, I think I may steal relavant bits from Eric's site for those servers.

Reboot VMGuests with delay

Advocacy is it's own reward. In our development and test VMware environments, some of our host systems are showing their age. We do Microsoft patch updates through SMS and if you reboot the environment at the same time, well, there are consequences. The most telling one is that services time out and fail to start, like the SMS service.

I was asked to come up with a manual staggered reboot method and it turns out to be remarkably simple.

Syndicate content