I am trying to retrieve GUIDs from SCCM and toss those in an SQL query, but I first need to get the GUIDs to perform the latter.
Here is a one-liner I put together that retrieves the GUIDs:
$SMSGUIDs = Get-CimInstance -NameSpace "root\SMS\site_$($SiteCode)" -ClassName SMS_StatMsgWithInsStrings -ComputerName $SiteServer |
Where-Object -FilterScript {$_.MessageID -eq '5446' -or $_.MessageID -eq '5447'} | Select-Object -Property InsString2 -Unique |
Out-String -OutVariable SMSGUIDs
However, the issue with this is that there are additional characters in the output that I do not want that look like this:
GUID:4c589841-12a5-4cf8-90b9-b4fe4bed0b2c
Client(SMSID = GUID:7d795378-4bb2-42cd-96fb-e3b7da7eaaba)
GUID:AB772008-BE74-4DBD-B9EB-8686830E91FE
Client(SMSID = GUID:7e36f7a0-9977-4b35-9cc1-e23bc29a649d)
GUID:ac9d940d-e30a-40b6-9036-f7a8869f1387
Client(SMSID = GUID:59dfc5a9-0e62-4531-bccf-2538021a5652)
Client(SMSID = GUID:d0ff6cb6-f347-4d07-8694-845d02407eda)
Client(SMSID = GUID:8b53edd3-682b-4eee-b721-28683c7398e5)
Client(SMSID = GUID:5bccf053-7e71-4652-8f52-1e9198b1099b)
GUID:cf7506bf-da70-4ddd-9454-414c19012107
GUID:4b1405fc-2e7c-487b-9721-c8140c9d4af7
GUID:3588B989-EB19-4330-BE16-C9DCFCD68728
Client(SMSID = GUID:c8cb1f89-fac3-47bb-bb73-0e5994fb2d19)
GUID:1ADD0309-E246-4211-B551-21E1A4B906F1
Client(SMSID = GUID:a09f5a1d-c4f2-4950-8094-e05de1f8704f)
I just need to filter out everything other than the GUIDs.
I tried this, but it did not work for me:
$SMSGUIDs -match("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")
Thank you