by Sentri at 2012-11-12 08:19:46
Hi All,by Sentri at 2012-11-12 13:00:15
A few weeks back I had a few questions that - through trial and error - was able to figure out. The following code is something I previously was able to use to change the owner of a SID. However, for reasons unknown, that same exact code no longer works and I’m mystified by this. Here is the code, as well as the error message:
$OriginalUser = gwmi win32_UserAccount -ComputerName testboxcpc -Filter "Name= ‘rcc2122’ AND LocalAccount=True"
$NewUser = gwmi "win32_UserAccount WHERE Name= ‘rcc2122’ AND Domain=‘Cul’"
$Profile = gwmi win32_UserProfile -ComputerName testboxcpc -filter "SID= ‘$($OriginalUser.SID)’"
$Profile.ChangeOwner($NewUser.SID,0)
Exception calling "ChangeOwner" : ""
At line:4 char:1
+ $Profile.ChangeOwner($NewUser.SID,0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ( , MethodInvocationException
+ FullyQualifiedErrorId : WMIMethodException
So I figured out what the problem was; I had logged in with both accounts for some reason and then tried running changeowner, which will obviously not work! It does work as it’s supposed to though, once I deleted the domain account and left the local account to be changed. However, I would like to know how this syntax works:by coderaven at 2012-11-26 07:08:56
gwmi win32_UserProfile -ComputerName testboxcpc -filter "SID= ‘$($OriginalUser.SID)’" – I’m unsure how the "SID= ‘$($OriginalUser.SID)’" portion of that line actually functions? Anyone have any idea? Thanks!
The line in question may function just because the WMI filter switch uses the WSQL syntax instead of the PowerShell syntax.