OK I’m not the best WMI guy around, so bear with me. Unless your SQL server is a domain controller, then I believe this is the issue.
$domainaccount = $User.Split('@')
$domain = $domainaccount.Split('.')
$accountname = $domainaccount
logToDisk "Domain: $domain"
logToDisk "Account: $accountname"
$domain = $computerName
$accountname = $User
logToDisk "Local system name: $domain"
The query is splitting the user up based on what you pass in. If it has an @ sign, it will get the first part of the domain. So email@example.com would get
$useraccount = 'User'
$domain = 'Domain'
In my testing on my SQL servers, Get-WmiObject -Class win32_useraccount only lists local accounts. the domain for those accounts are the local computer name. Only on the DC did I see the domain be the same as the actual domain. What I don’t understand is if you run this locally on that machine with the same user/format passed in, you should get the same results.
Unless the SQL server is a DC, I would try the command with either passing in just a local user name like ‘user’ or the local user name ‘user@computername’
Based on the way they split you could even put ‘user@computername.YouCanPutAnythingHereExceptAPeriod’ but that’s just silly. I hope i’m not wrong but that’s what my testing shows.
I hope this helps.