Skip to content

Tag: Powershell

PoSh – HP iLO – Configuring the iLO Hostname

If you’ve had any chance to use the HP Scripting Tools for Powershell at all you might have noticed some inconsistencies specific to the handling of server names. These issues are only made worse when combined with blade enclosures.

The biggest example to illustrate this is by using the get-hpiloservername cmdlet:
Get-HPiLOServerName Output

Now by going to the login screen of the iLO Management page we see:
HP iLO Management Page

Since this is a blade, let’s also see what the Onboard Administrator (OA) Device Bay Summary page says:
HP OA Output

According to the get-hpiloservername output the standard name should be updated to match that everywhere else. The setting in the GUI that we’re looking for is the “iLO Subsystem Name (Host Name)” which is located by way of the Network –> iLO Dedicated Network Port –> General tab area:
iLO Subsystem Name

Instead of reverse engineering the HP module, there’s a workaround available by way of the set-hpilonetworksetting, specifically the DNSName parameter. An example:
Set-HPiLONetworkSetting -Server '10.10.10.10' -DNSName 'newserver10' -Credentials (Get-Credential)

One big thing to note, this command does perform a reset against the iLO so if you’re connected to the iLO you will be kicked out and greeted by the following message:
iLO Reset

After the iLO finishes being reset, you can refresh the page and see the newly configured name:
HP iLO Management Page

Then returning to the OA Device Summary page:
HP OA Output

The next logical question is how to automate this process… That’s easy enough!

Let’s check out a section of IPs that are not yet configured with the get-hpilonetworksetting cmdlet:
iLO Hostname Output

Before we run the script, there are some assumptions this script makes:

  • You have the HP Scripting Tools for Powershell modules already installed.
  • You’re running Powershell version 4.0. That’s a requirement for the resolve-dnsname cmdlet to work.
  • DNS entries have already been made and are resolvable.
  • The login credentials are the same for all the iLO systems.

Making sure those bases are all covered it’s time to run the script:

Script output will appear similar to the following: (Note the differences in output)
Script Output

After giving it a minute or two for the iLO resets to be performed, we’ll check out the names again:
iLO Hostname Output

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PowerCLI – View – Pool Health Check Report

I’ve been given the chance to work with View a little more here recently and focus in on some of the gaps that are missing, specifically around reporting and alerting. vC Ops and the View adapter are in use, however the alerts leave much to be desired. I’m glad to be able to say that the gaps are filled in with the new version, and new title, of vR Ops and the View adapter but this environment is not yet to that point.

Examples of the vR Ops alerts which are included by default:

vR Ops Default View Alerts

What gaps am I referring to? I’m aiming specifically at the View Pool state, provisioning state and the amount of available desktops compared to the headroom configuration.

To do this, I enlisted the help of the View PowerCLI cmdlets and the View Connection server ADAM database to create the script below that creates an output similar to this:
(Note: the asterics around the value that caused the report to be sent)

View Pool Report Output

Before getting to the script, lets cover some of the requirements of the script:

  • This script is to be run from a Connection server.
  • This script is currently formatted to have the report be consumed by way of email.
  • The email variables need to be filled in to match the environment it’s being run in.
  • The email is sent only if the following criteria are met:
    • A Pool’s state is false.
    • A Pool’s provisioning state is false.
    • A Pool’s available desktops are less than the headroom setting by the amount set in the desktopthreshold variable.
  • The default desktop threshold is meant to be a percentage and is set to a default of 90%, or 0.9. This is easily modified on line 22.

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PowerCLI – Automate the vROps OVA Deployment

For those that haven’t heard, vCenter Operations (known better as vC Ops) has been not only updated but renamed. It’s new name is vRealize Operations (or, probably, vR Ops) and it is officially version 6.0. Previously the system was deployed in a vApp containing a UI VM and an Analytics VM. The new systems incorporates a roles for the VMs such as Master, Master Replica, Data and Remote Collecter.

However, this blog post isn’t to focus on what’s been updated. It’s to take a look at making the deployment a little easier since most installs will have at least two nodes. If you would like some further information on the update, please check out VMware’s website: http://www.vmware.com/products/vrealize-operations

After running the script below, you’ll find an output similar to the following:

vROps-Deploy

Before getting to the script, lets cover some of the assumptions and requirements made in the script:

  • The OVA has already been downloaded and is placed somewhere available to the system running the script. (Example: local disk, SMB or DFS share, etc.)
  • The VM is being placed in a resource pool.
  • The local system is able to successfully run and resolve the VM name via Resolve-DnsName cmdlet which is available in PowerShell v4.
  • The subnet being used is a /24 or 255.255.255.0. This is easily modified on line 126.
  • The VLAN ID is based on the third octet of the system’s IP address. This information is set on line 128 and the portgroup is set on line 133.
  • The gateway ends with ‘.254’. This is easily modified on line 129.
  • DNS should be modified to match your environment which is based on line 130.

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PowerCLI – Process of Adding Notes to VMs

Documentation is a good thing. No matter how big or small. One of the easiest methods of documentation is to use the built in annotation section for “Notes”.

Annotation Notes

What I’ve come up with is a fairly basic script to go through all the VM objects that do not contain notes and allow the user to insert notes on a line by line basis. Here’s an example:

Running the script

Here’s the script to accomplish it:

If a one-liner is more your speed, give this one a go… Note: you’ll have to specify your own cluster, if that’s a desired use.

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

View – Using Powershell to Check ADAM Replication Status

Recently ran into some issues where replication on the View ADAM database wasn’t going too well. Instead of checking the replication status by RDPing into each View Connection and running the repadmin command, I created a Powershell script to do it for me. This script also helped with verification due to being able to report all the Connection servers’ status within a single window.

Only item to note: you will have to prepopulate the script with the desired Connection servers

I also converted the above into a little more automated script that’s usable only from one of the Connection servers, thanks to how the View API ties into PowerCLI…

Items to note:

  • This has to be run through the View PowerCLI module, which only works on Connection servers.
  • It’s designed to be run as a one liner.
  • It will report back the replication status on all the Connection servers involved in that particular View environment.

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PoSh – Add File Share Permissions to Existing Share

Found myself in the position of having to add some permissions to an existing file share… Unfortunately none of these systems were 2012R2, whom can take advantage of the SMBShare cmdlets, so this ended up being a bigger task than I would’ve thought. I found tons of help and posts on creating shares, but found a surprising lack of information on a task of this nature which I would’ve thought fairly basic.

Couple things to note:

  • This only changes the actual file share permissions and does not touch the NTFS permissions.
  • There are 5 variables that need to be addressed prior to running the script.
  • One of those variables will require the Active Directory module imported to search specific OUs.
    The AD module isn’t a mandatory item, computer names can certainly be fed in one at a time or by way of an array.

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PowerCLI – Removing and Re-creating Unknown and/or Orphaned VMs

Ran into an issue lately where I found a host had lost its storage. For whatever reason HA didn’t kick in to bring all the VMs back to life and there was a need to recreate ~75 VMs whom were in an unknown and/or orphaned state. It looked a bit like this:
Unknown VMs

PowerCLI to the rescue!

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PowerCLI – One Liner – Finding Duplicate VMkernel IPs

Ever had issues with a host randomly disconnecting? vMotions randomly failing? iSCSI paths dropping? If so, there’s a chance you’re having issues with a duplicate IP on one of your VMkernel ports.

There’s no real way to display such information through the GUI, so I crafted a quick PowerCLI one-liner to accomplish this task:

Get-VMHost -ErrorAction SilentlyContinue | Get-VMHostNetworkAdapter -VMKernel | select VMHost,DeviceName,IP | Group-Object IP | where {$_.Count -gt 1} | %{$_.Group}

An example of what the output will look like if it finds any duplicate IPs:
PowerCLI - Duplicate VMkernel IPs

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

PowerCLI – Get-View View Types

Unfortunately, I don’t make use of the Get-View .NET cmdlet as often as I should. It’s a little more complicated than the rest of the PowerCLI cmdlets and a little harder to memorize but the speed is well worth the time and effort. Following up on that, this post is more for selfish reasons since I can never remember the proper ViewTypes. If you put in the wrong one the proper names all pop up but limiting the amount of red on my powershell screens is always a bonus.

PowerCLI Get-View View Types:

  • ComputeResource
  • ClusterComputeResource
  • Datacenter
  • Datastore
  • Network
  • DistributedVirtualPortgroup
  • DistributedVirtualSwitch
  • Folder
  • HostSystem
  • ResourcePool
  • VirtualApp
  • VirtualMachine
  • VmwareDistributedVirtualSwitch

PowerCLI – One-Liner – Check All VMHosts’ Time

It’s everyone’s favorite time of year, daylight savings time. If your NTP solution is solid, there’s no worries and you’ve never had to think twice about it. If you’re like everyone else, you at least want to run a couple scripts to verify and validate everything is looking good.

A little bit of background, the environment I was running this report on had 100+ hosts.

An easy one-liner:
Get-VMHost | sort Name | select Name,@{Name="Current VMHost Time";Expression={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem).QueryDateTime()}}

Depending on the size of your environment, this could take 20 seconds or an hour. In my case, it took 14 minutes. However, due to the time it took to run, quite a few hosts were reporting different times. A discrepancy of 14 minutes either way meant that the hosts were all just about in sync. If you’re only worried about time zone issues, a 14 minute discrepancy is acceptable.

Example based upon the environment I was working in:
PowerCLI C:\ > Get-Date -Format g; Get-VMHost | sort Name | select Name,@{Name="Current VMHost Time";Expression={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem).QueryDateTime()}}; Get-Date -Format g

10/9/2013 10:19 AM
Name Current VMHost Time
---- -------------------

10/9/2013 10:33 AM

At this point you may be thinking, there has to be a faster way to do this. You’re right, there is. To do so, you have to leave the comfort of the PowerCLI cmdlets behind and make a swap over to the .NET view objects cmdlets. In this case, Get-View will be used.

Good news, it is still another one-liner:
Get-View -ViewType HostSystem -Property Name,ConfigManager.DateTimeSystem | sort Name | select Name,@{Name="Current VMHost Time";Expression={(Get-View $_.ConfigManager.DateTimeSystem).QueryDateTime()}}

As you can see, there’s a bit of a difference between the one-liners and there will be a bit of a learning curve as well. The time savings will be worth it though. To prove it, this version only took 2 minutes to run. That’s a 12 minute savings!

Example based upon the environment I was working in:
PowerCLI C:\ > Get-Date -Format g; Get-View -ViewType HostSystem -Property Name,ConfigManager.DateTimeSystem | sort Name | select Name,@{Name="Current VMHost Time";Expression={(Get-View $_.ConfigManager.DateTimeSystem).QueryDateTime()}}; Get-Date -Format g

10/9/2013 10:35 AM

Name Current VMHost Time
---- -------------------

10/9/2013 10:37 AM

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.