Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove string after expected value

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?

like image 640
Notumlord Avatar asked Jun 13 '26 20:06

Notumlord


1 Answers

Split the string using a regular expression

To exactly follow your definition "break off after the Server":

($r.OS -Split "(?<=\WServer\W)")[0]
like image 86
iRon Avatar answered Jun 17 '26 01:06

iRon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!