How to use Win32_UserAccount rename method? The Next CEO of Stack OverflowHow to run a PowerShell scriptHow do you comment out code in PowerShell?How to filter Win32_UserAccount results by OUWMI IIS 6.0 Custom HttpError (Powershell)PowerShell Rename-Computer issue — names with underscoresScript to add days to a parameterUsing Powershells Trimstart to remove array of characters from filenameError in executing Exchange PS remoting: Method invocation failed?Powershell Exception: Not enough quota is available to process this commandPSWindowsUpdate File Not Found Exception

Does higher Oxidation/ reduction potential translate to higher energy storage in battery?

Audio Conversion With ADS1243

Is fine stranded wire ok for main supply line?

Is it okay to majorly distort historical facts while writing a fiction story?

How did Beeri the Hittite come up with naming his daughter Yehudit?

Can I calculate next year's exemptions based on this year's refund/amount owed?

Help/tips for a first time writer?

Could a dragon use its wings to swim?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Easy to read palindrome checker

What CSS properties can the br tag have?

Is a distribution that is normal, but highly skewed, considered Gaussian?

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

From jafe to El-Guest

Is it ok to trim down a tube patch?

Reshaping json / reparing json inside shell script (remove trailing comma)

What does "shotgun unity" refer to here in this sentence?

Which one is the true statement?

Getting Stale Gas Out of a Gas Tank w/out Dropping the Tank

Can Sneak Attack be used when hitting with an improvised weapon?

Do scriptures give a method to recognize a truly self-realized person/jivanmukta?

What are the unusually-enlarged wing sections on this P-38 Lightning?

Where do students learn to solve polynomial equations these days?

Why do we say 'Un seul M' and not 'Une seule M' even though M is a "consonne"



How to use Win32_UserAccount rename method?



The Next CEO of Stack OverflowHow to run a PowerShell scriptHow do you comment out code in PowerShell?How to filter Win32_UserAccount results by OUWMI IIS 6.0 Custom HttpError (Powershell)PowerShell Rename-Computer issue — names with underscoresScript to add days to a parameterUsing Powershells Trimstart to remove array of characters from filenameError in executing Exchange PS remoting: Method invocation failed?Powershell Exception: Not enough quota is available to process this commandPSWindowsUpdate File Not Found Exception










0















I am able to use Get-CimInstance Win32_UserAccount to list users on remote computers. Once I get the users, I would like to rename the administrator account. Below is the code but it does not work. Any tips on making this work?



$hostname = "SERVER1"
$newname = "Server_Admin"
$administrator = Get-CimInstance Win32_UserAccount -ComputerName $hostname |
where SID -like 'S-1-5-*-500' -ErrorAction SilentlyContinue
$oldname = $administrator.Name

$oldname.Rename($newname)


Above command failed with the error




Method invocation failed because [System.String] does not contain a method named 'rename'.




Using Set-CimInstance



Set-CimInstance -InputObject $administrator -Property @name=$newname -PassThru


gives an error




Could not modify readonly property 'name' of object 'Win32_UserAccount"




PowerShell version used is 5.1.










share|improve this question




























    0















    I am able to use Get-CimInstance Win32_UserAccount to list users on remote computers. Once I get the users, I would like to rename the administrator account. Below is the code but it does not work. Any tips on making this work?



    $hostname = "SERVER1"
    $newname = "Server_Admin"
    $administrator = Get-CimInstance Win32_UserAccount -ComputerName $hostname |
    where SID -like 'S-1-5-*-500' -ErrorAction SilentlyContinue
    $oldname = $administrator.Name

    $oldname.Rename($newname)


    Above command failed with the error




    Method invocation failed because [System.String] does not contain a method named 'rename'.




    Using Set-CimInstance



    Set-CimInstance -InputObject $administrator -Property @name=$newname -PassThru


    gives an error




    Could not modify readonly property 'name' of object 'Win32_UserAccount"




    PowerShell version used is 5.1.










    share|improve this question


























      0












      0








      0








      I am able to use Get-CimInstance Win32_UserAccount to list users on remote computers. Once I get the users, I would like to rename the administrator account. Below is the code but it does not work. Any tips on making this work?



      $hostname = "SERVER1"
      $newname = "Server_Admin"
      $administrator = Get-CimInstance Win32_UserAccount -ComputerName $hostname |
      where SID -like 'S-1-5-*-500' -ErrorAction SilentlyContinue
      $oldname = $administrator.Name

      $oldname.Rename($newname)


      Above command failed with the error




      Method invocation failed because [System.String] does not contain a method named 'rename'.




      Using Set-CimInstance



      Set-CimInstance -InputObject $administrator -Property @name=$newname -PassThru


      gives an error




      Could not modify readonly property 'name' of object 'Win32_UserAccount"




      PowerShell version used is 5.1.










      share|improve this question
















      I am able to use Get-CimInstance Win32_UserAccount to list users on remote computers. Once I get the users, I would like to rename the administrator account. Below is the code but it does not work. Any tips on making this work?



      $hostname = "SERVER1"
      $newname = "Server_Admin"
      $administrator = Get-CimInstance Win32_UserAccount -ComputerName $hostname |
      where SID -like 'S-1-5-*-500' -ErrorAction SilentlyContinue
      $oldname = $administrator.Name

      $oldname.Rename($newname)


      Above command failed with the error




      Method invocation failed because [System.String] does not contain a method named 'rename'.




      Using Set-CimInstance



      Set-CimInstance -InputObject $administrator -Property @name=$newname -PassThru


      gives an error




      Could not modify readonly property 'name' of object 'Win32_UserAccount"




      PowerShell version used is 5.1.







      powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 19:32









      Ansgar Wiechers

      146k13132190




      146k13132190










      asked Mar 21 at 18:43









      Dev Ops 52Dev Ops 52

      1




      1






















          2 Answers
          2






          active

          oldest

          votes


















          0














          in that use case, the CIM cmdlet DOES NOT return a live object. there is NO .Rename() method attached to that object.



          however, the WMI cmdlet DOES return a live object with a .Rename() method. so ... use Get-WmiObject -Class Win32_UserAccount instead of Get-CimInstance -ClassName Win32_UserAccount. [grin]






          share|improve this answer






























            0














            Using PowerShell version 5.1



            Using Invoke-CIMMethod I was able to rename the account.



            $serverlist = Get-Content C:Tempservers.txt
            $newname = "Server_Admin"

            foreach ($hostname in $serverlist)

            #Check if server is online.
            if (Test-Connection -ComputerName $hostname -Count 1 -Delay 2 -BufferSize 1452 -Quiet)
            sort Status






            share|improve this answer








            New contributor




            Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287254%2fhow-to-use-win32-useraccount-rename-method%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              in that use case, the CIM cmdlet DOES NOT return a live object. there is NO .Rename() method attached to that object.



              however, the WMI cmdlet DOES return a live object with a .Rename() method. so ... use Get-WmiObject -Class Win32_UserAccount instead of Get-CimInstance -ClassName Win32_UserAccount. [grin]






              share|improve this answer



























                0














                in that use case, the CIM cmdlet DOES NOT return a live object. there is NO .Rename() method attached to that object.



                however, the WMI cmdlet DOES return a live object with a .Rename() method. so ... use Get-WmiObject -Class Win32_UserAccount instead of Get-CimInstance -ClassName Win32_UserAccount. [grin]






                share|improve this answer

























                  0












                  0








                  0







                  in that use case, the CIM cmdlet DOES NOT return a live object. there is NO .Rename() method attached to that object.



                  however, the WMI cmdlet DOES return a live object with a .Rename() method. so ... use Get-WmiObject -Class Win32_UserAccount instead of Get-CimInstance -ClassName Win32_UserAccount. [grin]






                  share|improve this answer













                  in that use case, the CIM cmdlet DOES NOT return a live object. there is NO .Rename() method attached to that object.



                  however, the WMI cmdlet DOES return a live object with a .Rename() method. so ... use Get-WmiObject -Class Win32_UserAccount instead of Get-CimInstance -ClassName Win32_UserAccount. [grin]







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 21 at 19:42









                  Lee_DaileyLee_Dailey

                  2,5911811




                  2,5911811























                      0














                      Using PowerShell version 5.1



                      Using Invoke-CIMMethod I was able to rename the account.



                      $serverlist = Get-Content C:Tempservers.txt
                      $newname = "Server_Admin"

                      foreach ($hostname in $serverlist)

                      #Check if server is online.
                      if (Test-Connection -ComputerName $hostname -Count 1 -Delay 2 -BufferSize 1452 -Quiet)
                      sort Status






                      share|improve this answer








                      New contributor




                      Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.
























                        0














                        Using PowerShell version 5.1



                        Using Invoke-CIMMethod I was able to rename the account.



                        $serverlist = Get-Content C:Tempservers.txt
                        $newname = "Server_Admin"

                        foreach ($hostname in $serverlist)

                        #Check if server is online.
                        if (Test-Connection -ComputerName $hostname -Count 1 -Delay 2 -BufferSize 1452 -Quiet)
                        sort Status






                        share|improve this answer








                        New contributor




                        Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          0












                          0








                          0







                          Using PowerShell version 5.1



                          Using Invoke-CIMMethod I was able to rename the account.



                          $serverlist = Get-Content C:Tempservers.txt
                          $newname = "Server_Admin"

                          foreach ($hostname in $serverlist)

                          #Check if server is online.
                          if (Test-Connection -ComputerName $hostname -Count 1 -Delay 2 -BufferSize 1452 -Quiet)
                          sort Status






                          share|improve this answer








                          New contributor




                          Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          Using PowerShell version 5.1



                          Using Invoke-CIMMethod I was able to rename the account.



                          $serverlist = Get-Content C:Tempservers.txt
                          $newname = "Server_Admin"

                          foreach ($hostname in $serverlist)

                          #Check if server is online.
                          if (Test-Connection -ComputerName $hostname -Count 1 -Delay 2 -BufferSize 1452 -Quiet)
                          sort Status







                          share|improve this answer








                          New contributor




                          Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered Mar 25 at 20:16









                          Dev Ops 52Dev Ops 52

                          1




                          1




                          New contributor




                          Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Dev Ops 52 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid …


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287254%2fhow-to-use-win32-useraccount-rename-method%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                              Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?