I'm writing a short script that compares the OS running on our VM's against what we have manually entered into our CMDB. Below is some test code
foreach ($r in $SQL) {
if ((Get-VMGuest $r.name).OSFullName -eq $r.OS) {
Write-Host "Match"
} else {
Write-Host "Not matching"
}
}
Here is some example output
VM Output = Microsoft Windows Server 2003 Standard (32-bit)
SQL Output = Microsoft Windows Server 2003, Standard Edition
VM Output = Microsoft Windows Server 2012 (64-bit)
SQL Output = Microsoft Windows Server 2012 Standard
Since the way the result is outputted i never get a match even though the OS are the same.
Is there a way to break off after the Server year or another way to get around this?
Split the string using a regular expression
To exactly follow your definition "break off after the Server":
($r.OS -Split "(?<=\WServer\W)")[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With