Research Triangle PowerShell Saturday – September 21st

Time is running out to attend the Research Triangle PowerShell Saturday. The main conference is on Saturday, September 21st, 2019 in Raleigh, North Carolina. There’s also a concentrated 6-hour security session on Sunday, September 22nd.

Tickets can be purchased for one day or both. Seating is limited, however, for the Sunday security session, so get your tickets sooner than later.

The three different tracks on Saturday cover the whole gambit of PowerShell scripting and development as it currently stands. Details about the presenters are here.

  • PowerShell 101 – Intro and Fundamentals
    • Use Default Formats to Improve Your Quality of Life – Jeremy Smith
    • Filtering Files at Scale – Mark Hutchenson
    • PowerShell 101 – Arrays – Wes Carroll
    • PowerShell Streams and Using the Right Write-* Cmdlet – Justin Gehman
    • The Ins and Outs of Error Handling – David Littlejohn
    • Why you should be using PSReadline everyday – Jeffery Hayes
  • PowerShell Tools – Advanced Scripting and Tools
    • GitHub for PowerShell Users – Bryce McDonald
    • Using Dbatools To Automate Database Migrations – Joshua Corrick
    • Don’t do what I did! Avoiding Azure $urprise$! – Michael Teske
    • Why can’t we be friends? Command Line Utilities + PowerShell = ❤ – Ryan Leap
    • What to do when .NET isn’t enough – Jason Walker
    • Don’t Reinvent Another Wheel if You Don’t Have To – David Stein
  • DevOps & Security – DevOps, CI\CD and Security
    • PowerShell Security 102? – Jon Fox
    • Securing PSRemoting – James Petty
    • Crossing the Divide – A System Administrator’s Path to DevOps – Dave Carroll
    • Securing Windows 10 with PowerShell Compliance items in SCCM – Jon Warnken
    • Gaining 20/20 vision during an incident with PowerShell – Fernando Tomlinson
    • Code. Commit. Deploy. Starting your 3 step journey to utilizing Pipelines – Stephen Valdinger

Keep checking the conference site as more details about the schedule will be posted. You will be able to move between tracks, but each track will run in parallel. Lunch and snacks are provided as part of the conference fee and parking is free.

Hope to see you there,

PowerShell: XenServer Count Function



I’ve been hesitant to dive into XenServer PowerShell cmdlets, but there’s no rational reason to not do it. Citrix continues to make great strides in expanding and updating PowerShell for XenServer, PVS, and XenDesktop. Today, we’ll go over a function that queries an array of XenServer Poolmasters and returns the total VM count on each. The idea behind this function was to stop manually counting VM’s in XenCenter and to understand VM growth and XenServer Pool utilization.

NOTE: Thanks to The Scripting Frog for getting me most of the way there with this function.

The manual count of VM’s

XenServer and PowerShell?

It may seem weird to use PowerShell to perform queries of a Linux-based system, but such is the world we live in. I remember back in my day :). Apple was a joke, IBM ruled the PC market and Linux didn’t exist. Of course I still remember saving BASIC programs to a cassette deck.


The script will prompt for credentials which can be root or any XenServer administrator. Then you connect to each pool master in turn…

# Loop through list of hosts (poolmaster)
$xenserver_poolmaster | ForEach-Object {
# Connect to XenServer pool
Connect-XenServer Server $_ Creds $xenserver_credential SetDefaultSession NoWarnNewCertificates

view raw
hosted with ❤ by GitHub

The important flags are -SetDefaultSession and -NoWarnNewCertificates. You must set the default session on each new XenServer connection, otherwise, the script will not know what pool master to query. The NoWarnNewCertificates flag prevents a prompt asking you to accept the new XenServer certificate (you can leave this out if you want this additional warning to let you know you’re connecting to a new XenServer).

Unless you can refer to your XenServers with a DNS name, you can do some quick translation to make your output more readable. I’m using a switch statement to replace the IP address with a XenServer name.

switch ($_) {
"" {$xsn = "XenServerPool1"; break}
"" {$xsn = "XenServerPool2"; break}
default {"UNKNOWN XENSERVER"; break}

view raw
hosted with ❤ by GitHub

The rest is just getting all the VM’s (minus snapshots, templates, etc), counting them and putting the results into a custom PowerShell Object. Finally you disconnect from each XenServer and go to the next one.

# Retrieve the information
$XenServerVMs = Get-XenVM | Where-Object {$_.is_a_snapshot -eq $false -and $_.is_a_template -eq $false -and $_.is_control_domain -eq $false -and $_.power_state -eq 'running'} | Select-Object name_label
$vmCount = $XenServerVMs.count
$objctxsrv = new-object System.Object
$objctxsrv | Add-Member type NoteProperty name XenServer value $xsn
$objctxsrv | Add-Member type NoteProperty name 'VM Count' value ($vmCount)
$finalout += $objctxsrv
# Disconnect from the XenServer pool
Get-XenSession Server $_ | Disconnect-XenServer

view raw
hosted with ❤ by GitHub

The results…

XenServer VM Count
--------- --------
XenServerPool1 108
XenServerPool2 109

You can get this and so much more from my github.

Thanks for reading,
Alain Assaf

RTP PowerShell User Group: Adding Scheduled Jobs to your PowerShell Toolbox – July 25th.

July 25th, the Research Triangle PowerShell User Group will host Jeff Hicks. He will cover implementing PowerShell scripts with Scheduled Jobs. It proves to be an informative meeting. Check more at MeetUp –