Category Archives: Infrastructure

Getting the username of snapshot owners/creators in vSphere

Have you ever taken a snapshot of a virtual machine that you forgot to delete afterwards? Me too.

If snapshots never get deleted they can grow in size and affect the performance and stability of the virtual machine.

The “Get-Snapshot”-cmdlet does not contain the username of the admin who took the snapshot, therefor I wrote an advanced function that can get this information.

I know there are other scripts for doing this, but those did not work in our environment and instead of debugging them it was easier to just create a new one 🙂

I’m guessing a lot of you have different accounts for administering vSphere and using e-mail, so you might need to parse the username you get back before looking up the users e-mail in Active Directory, and since this is probably pretty specific for your environment I didn’t see much of a reason to publish the script we use to loop through the snapshots.

But get the username from the function, check when the snapshot is created (CreatedTime) and if it is greater than your threshold then send out an e-mail, and you are done 🙂

The function returns the name of the VM, the size of the snapshot (in mb), the name of the snapshot, Id of the snapshot, the Creator (username) and the time when it was created.

The code for this function is available here.

I would also like to credit Dave Garnar who did most of the heavy lifting in figuring out where to find the username information and was kind enough to post it in this post. I basically just created an advanced function out of it, nothing fancy.

Let’s build a Infoblox PowerShell Module!

If you haven’t heard of it, Infoblox is making appliances and solutions for enterprise networks. One of them is the Infoblox Trinzic DDI which manages DNS, DHCP and IPAM.

Infoblox does not seem to have any plans for delivering a PowerShell module for managing their product, which is a bit weird since it would probably make it a bit easier for network admins trying to move windows engineers away from Active Directory Integrated DNS, and instead let the Infoblox appliance host all or some of their zones (which seems to be a common enough debate among enterprises).
But in their defence they have released a REST-based API for this appliance which enables administrators to basically build whatever tools they want to manage anything from DNS records to IPAM.

I’ve therefore started to build a module for managing DNS-records hosted by the Infoblox, but since my experience with this product is fairly limited, I thought I would post what I’ve done so far to get opinions from people with more experience with this product.

I’ve only done a few cmdlets (advanced functions) for managing a few common DNS record tasks. So far these are:

  • Add-IBResourceRecordA
  • Add-IBResourceRecordCName
  • Add-IBResourceRecordHost
  • Get-IBResourceRecord
  • Remove-IBResourceRecord
  • Set-IBResourceRecord

Some usage examples:

# Adding a A-record
Add-IBResourceRecordA -IPv4Address 1.2.3.4 -HostName myhost.contoso.com -GridServer $MyInfobloxGrid -Credential $MyCredential

# Adding a hundred A-records
1..100 | % { Add-IBResourceRecordA -IPv4Address 1.2.3.$_ -HostName myhost$_.contoso.com -GridServer $MyInfobloxGrid -Credential $MyCredential }

# Searching for those records
Get-IBResourceRecord -RecordType A -RecordValue myhost* -GridServer $MyInfobloxGrid -Credential $MyCredential

# Search for a record by IP-address
Get-IBResourceRecord -RecordType A -SearchField ipv4addr -RecordValue 1.2.3.4 -GridServer $MyInfobloxGrid -Credential $MyCredential

# Removing all of them
Get-IBResourceRecord -RecordType A -RecordValue myhost* -GridServer $MyInfobloxGrid -Credential $MyCredential -Passthrough | Remove-IBResourceRecord

# Add a HOST record
Add-IBResourceRecordHost -IPv4Address 1.2.3.4 -HostName myhost.contoso.com -GridServer $MyInfobloxGrid -Credential $MyCredential

# Change the IP-address of that record (A-record needs some tweaking before they work, I'm working on it...)
Get-IBResourceRecord -RecordType Host -RecordValue myhost.contoso.com -GridServer $MyInfobloxGrid -Credential $MyCredential -Passthrough | Set-IBResourceRecord -IPv4Address 4.3.2.1

# Add a CName
Add-IBResourceRecordCName -HostName cname.contoso.com  -Canonical myhost2.contoso.com -GridServer $MyInfobloxGrid -Credential $MyCredential

Screenshot:
Infoblox module in action...

This is very early in the development of this module, so it probably have a few bugs, and there are a lot of cmdlets that needs to be written!

Anyone out there that wants help or have any thoughts?

Please post a comment here or join this thread in the Infoblox community forum.

The code for this early version of the module is available at the Github repo!

Get local groups and their members with PowerShell

The Active Directory Module for PowerShell is great. You can do almost anything with it, but every now and then you might need to list the local groups and their members on a server/client, and that is harder…

To achieve this I wrote a couple of advanced functions to simplify the task. “Get-LocalGroup” and “Get-LocalGroupMember”.

The usage should be pretty simple, but to give you an idea:

PS H:\> Get-LocalGroup

ComputerName GroupName                                   SID
------------ ---------                                   ---
MyMachine    Administrators                              S-1-5-32-544
MyMachine    Backup Operators                            S-1-5-32-551
MyMachine    Cryptographic Operators                     S-1-5-32-569
MyMachine    Distributed COM Users                       S-1-5-32-562
MyMachine    Event Log Readers                           S-1-5-32-573
MyMachine    Guests                                      S-1-5-32-546
MyMachine    IIS_IUSRS                                   S-1-5-32-568
MyMachine    Network Configuration Operators             S-1-5-32-556
MyMachine    Performance Log Users                       S-1-5-32-559
MyMachine    Performance Monitor Users                   S-1-5-32-558
MyMachine    Power Users                                 S-1-5-32-547
MyMachine    Remote Desktop Users                        S-1-5-32-555
MyMachine    Replicator                                  S-1-5-32-552
MyMachine    Users                                       S-1-5-32-545


PS H:\> Get-LocalGroup | where GroupName -eq Administrators | Get-LocalGroupMember

Domain    GroupName      Type  Name
------    ---------      ----  ----
MyMachine Administrators User  Administrator
MyDomain  Administrators Group Domain Admins
MyDomain  Administrators Group TheAdmins

The code is available here.