I need assistance on creating a regex to differentiate between a Domain and local account. I have the following in my code
$computer = 'servername'
$dom-regexp = "^WinNT://(?\w+)/(?.+)"
$loc-regexp = "^WinNT://\w+/$computer/(?\w+)"
#input strings are as follows:
$dom = "WinNT://Domain/ConfigMgr" #(represents a domain object)
$loc = "WinNT://Domain/$computer/ConfigMgr" #(represents a local object on server)
$loc -match $dom-regexp returns as true because of /.+ in the regex which is not valid data. I tried playing with assertions but no luck yet.
$matches returns:
Name Value
---- -----
ADObject servername/ConfigMgr
Domain DOMAIN
0 WinNT://DOMAIN/servername/ConfigMgr
Local object matches works fine but if the regex could be improved it will be greatly appreciated.
Thank you Curtis. My apologies for not providing a clearer picture of my problem but that also will provide me with false positive. I am essentially querying servers based on groups provided during runtime. I will get a list of memberof the group. Which I then need to differentiate between local accounts and domain accounts and extract the local username or ADObject. Once I have this information I query the respective source for that user/group (local or domain).
Your regex works but it will also produce false positive with BuiltIN accounts.