System Center

PowerShell function to parse Netstat output and return a PowerShell object


This is a function to parse Netstat -ano output and return a PowerShell object.

This output is similar to that of the Get-NetTCPConnection cmdlet of the NetTCPIP PowerShell module.

To see the built-in help, type in: help Parse-Netstat -Show

Example:

(Parse-Netstat | where { $_.Version -eq ‘IPv4’ -and $_.RemoteAddress -ne ‘0.0.0.0’ -and $_.LocalPort -eq 5985 } | select RemoteAddress -Unique).RemoteAddress

This example checks for connections where localhost is listening on TCP port 5985 (VMM Agent which uses WBEM WS-Management HTTP), and returns the IP address of the remote host (VMM server). VMM being System Center Virtual Machine Manager. If it returns nothing, this means this machine is not listening on port 5985 (VMM agent not running)

Example:

vmm1

Advertisements

NJ PowerShell User Group January 8th 2015 Meetup


Yesterday, I attended last evening’s NJ PowerShell User Group January 8th Meetup online. It was attended by a nice group including Jeffrey Snover the godfather of PowerShell, and half a dozen or so MVPs including Joel Bennett, Dave Jones, Trevor Sullivan, Keith Hill, Kirk Munro, Jason Milczek, and Dave Wyatt. The System Center folks may find the first link interesting.

The main subject was PowerShell 5. Interesting links from the meetup include:


Image

Live migration fails of Private Cloud VMs after using PDT


no-live-migrationIf you try to live migrate the Private Cloud VMs after using the PDT VMCreator.ps1 you’ll get an error similar to this:

The reason is that the OS disk in each of the 15 VMs is a differencing disk. To convert all 15 disks from Differencing to Dynamic, I developed the following Powershell script:

# Script to convert Differencing Disk to Dynamic on all VMs on current host
# Sam Boutros
# 6/2/2014
# Convert-DiffDisk.ps1
# Needed after using PDT to create private cloud VMs – cannot live-migrate VMs with differencing disks
#
$Loc = Get-Location
$Archive = $Loc.Path + “\Delete.me”
new-item $Archive -type directory -ErrorAction SilentlyContinue
$Date = Get-Date -format yyyyMMdd_hhmmsstt
$logfile = $Loc.path + “\Convert_” + $Date + “.txt”
#
function log($string, $color)
{
if ($Color -eq $null) {$color = “white”}
write-host $string -foregroundcolor $color # Sorry Don Jones 🙂
$temp = “: ” + $string
$string = Get-Date -format “yyyy.MM.dd hh:mm:ss tt”
$string += $temp
$string | out-file -Filepath $logfile -append
}
#
function Convert_Disk0($VM)
{
$Disk0 = Get-VMHardDiskDrive -VMName $VM -ControllerType IDE
$Source = $Disk0.Path
$Destination = $Source.Insert($Source.IndexOf(“.vhdx”,1),”_C1″)
log “Stopping $VM VM” green
Stop-VM -Name $VM
log “Converting disk $Source” green
Convert-VHD -DestinationPath $Destination -Path $Source -VHDType Dynamic
log “Attaching new disk $Destination to $VM” green
Get-VMHardDiskDrive -VMName $VM -ControllerType IDE | Set-VMHardDiskDrive -Path $Destination
log “Starting $VM VM” green
Start-VM -Name $VM
log “Moving old disk file $Source to $Archive folder” green
Move-Item $Source $Archive
}
#
$VMs = Get-VM -ComputerName $env:COMPUTERNAME
# To convert the IDE disk on all VMs on the current host use the following line:
# Foreach ($VM in $VMs.Name) { Convert_Disk0 $VM }
# To convert the IDE disk of a single VM use the following line – replace “VMM01” as needed:
Convert_Disk0 “VMM01”


PDT error ADK81\adksetup.exe incorrect version


Background:

PDT is the Powershell Deployment Toolkit for System Center developed by Rob Willis of Microsoft.


Issue:

When you run the PDT VMCreator.ps1 script you get error:

..Failed ADK81 incorrect version

ADK81


Solution:

Edit line 2828 of workflow.xml changing it from:

<FileVersion>8.100.26020</FileVersion>

to:

<FileVersion>8.100.26629</FileVersion>

This is the current version (as of 5/24/2014) of adksetup.exe which is located under Installer\Prerequisites\ADK81 folder:

ADK81b


Alternative work- around:

You can run VMCreator.ps1 with the -SkipValidation switch