Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, March 30, 2018 5:49 PM
Hello,
I am trying the below script to read a text file of computers and rename the local administrator account but encountering an error.
Please advise how to fix.
Thanks.
$computers = Get-Content -path C:\computers.txt
$accountname = Read-Host -prompt "Enter new accountname for administrator" -assecurestring
$decodedaccountname = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($accountname))
Foreach($computer in $computers)
{
$computer
$user = [adsi]"WinNT://$computer/administrator,user"
$user.administrator.rename("newlocaladmin_name")
$user.SetInfo()
}
All replies (5)
Friday, March 30, 2018 6:37 PM âś…Answered
** $user.Name = 'new_name'**
Regards kvprasoon
Not according to google
$admin=[adsi]"WinNT://./Administrator,user"
$admin.psbase.rename("NewUserNameHERE")
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
Friday, March 30, 2018 5:51 PM
So you are encountering an error, but didn't think it would be helpful to actually post the error you are having?
Let me see if my Jedi Mind reading trick works..........nope it doesn't
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
Friday, March 30, 2018 6:08 PM
Method invocation failed because [System.Management.Automation.PSMethod] does not contain a method named 'rename'.
At C:\chgacctname.ps1:8 char:2
+ $user.administrator.rename("newlocaladmin")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Friday, March 30, 2018 6:22 PM
try $user.psbase.rename()
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
Friday, March 30, 2018 6:28 PM
** $user.Name = 'new_name'**
Regards kvprasoon