AD Delegated user password changeSaving credentials for reuse by powershell and error ConvertTo-SecureString : Key not valid for use in specified statePowerShell script to store passwords failsConnect Office 365 Exchange Online through PowershellPowerShell - how to set mailbox to a user in Exchange 2003 remotely from a Win2008 serverImport-CliXML fails when called within a constrained sessionOpening a powershell with credentials in memoryJenkins slave enabling using Powershell remotelyHow to create a credential of my current user?Encrypting Password across different systems in PowershellGet-Content -Path not working in script run by Certify (Lets Encrypt) but runs fine when script is run in powershell

Are there any rules for identifying what spell an opponent is casting?

For Saintsbury, which English novelists constituted the "great quartet of the mid-eighteenth century"?

Does PC weight have a mechanical effect?

Struggling to present results from long papers in short time slots

How do I become a better writer when I hate reading?

At what temperature should the earth be cooked to prevent human infection?

Why did the USA sell so many airplanes prior to WW2?

Print the phrase "And she said, 'But that's his.'" using only the alphabet

Why doesn't Mathematica completely draw the fit?

Fastest path on a snakes and ladders board

Threading data on TimeSeries

Does an African-American baby born in Youngstown, Ohio have a higher infant mortality rate than a baby born in Iran?

Can I appeal credit ding if ex-wife is responsible for paying mortgage?

Arcane Tradition and Cost Efficiency: Learn spells on level-up, or learn them from scrolls/spellbooks?

Can I give my friend the sour dough "throw away" as a starter to their sourdough starter?

I sent an angry e-mail to my interviewers about a conflict at my home institution. Could this affect my application?

100-doors puzzle

IIS LAN and WAN separate SSL certificates for the same server

What does the output current rating from an H-Bridge's datasheet really mean?

Improving do loop speed with IntegerQ conditions

Does anyone recognize these rockets, and their location?

My parents claim they cannot pay for my college education; what are my options?

Background for black and white chart

How to search for Android apps without ads?



AD Delegated user password change


Saving credentials for reuse by powershell and error ConvertTo-SecureString : Key not valid for use in specified statePowerShell script to store passwords failsConnect Office 365 Exchange Online through PowershellPowerShell - how to set mailbox to a user in Exchange 2003 remotely from a Win2008 serverImport-CliXML fails when called within a constrained sessionOpening a powershell with credentials in memoryJenkins slave enabling using Powershell remotelyHow to create a credential of my current user?Encrypting Password across different systems in PowershellGet-Content -Path not working in script run by Certify (Lets Encrypt) but runs fine when script is run in powershell






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to write a code in PowerShell that will loop till the user would like to exit. Thus, allowing the delegated user to change passwords for student accounts.



I have tested the code for the password change and it works without any issues.



As soon as I try adding a while loop the code wont run.



#Open powershell as Administrator
Start-process Powershell -verb RunAs

# Connect to the Domain Controller
$session = New-PSSession -ComputerName "" -Credential (Get-Credential)
Invoke-Command $session -Scriptblock Import-Module ActiveDirectory
Import-PSSession -session $session -Module ActiveDirectory

#verify that you're connectedto the Domain
Get-ADDomainController -Filter * | Select-Object name

#run Password Change
$userid = Read-Host -Prompt 'Please enter the studnets login ID'
$newPassword = Read-Host -Prompt 'Please enter the studnets new password'

$run = 'yes'
while ($run -eq 'yes')

if (Get-ADUser -Filter SamAccountName -eq $userid)

Set-ADAccountPassword $userid -Reset -NewPassword (ConvertTo-SecureString -Force -AsPlainText '$newPassword')
Write - Host "$userid` password has now been changed to: $newPassword"

else

Write - Host "$userid` does not exist, please try again."

$answer = Read-Host -Prompt 'Would you like to change another studnets password? [y









share|improve this question






























    0















    I'm trying to write a code in PowerShell that will loop till the user would like to exit. Thus, allowing the delegated user to change passwords for student accounts.



    I have tested the code for the password change and it works without any issues.



    As soon as I try adding a while loop the code wont run.



    #Open powershell as Administrator
    Start-process Powershell -verb RunAs

    # Connect to the Domain Controller
    $session = New-PSSession -ComputerName "" -Credential (Get-Credential)
    Invoke-Command $session -Scriptblock Import-Module ActiveDirectory
    Import-PSSession -session $session -Module ActiveDirectory

    #verify that you're connectedto the Domain
    Get-ADDomainController -Filter * | Select-Object name

    #run Password Change
    $userid = Read-Host -Prompt 'Please enter the studnets login ID'
    $newPassword = Read-Host -Prompt 'Please enter the studnets new password'

    $run = 'yes'
    while ($run -eq 'yes')

    if (Get-ADUser -Filter SamAccountName -eq $userid)

    Set-ADAccountPassword $userid -Reset -NewPassword (ConvertTo-SecureString -Force -AsPlainText '$newPassword')
    Write - Host "$userid` password has now been changed to: $newPassword"

    else

    Write - Host "$userid` does not exist, please try again."

    $answer = Read-Host -Prompt 'Would you like to change another studnets password? [y









    share|improve this question


























      0












      0








      0








      I'm trying to write a code in PowerShell that will loop till the user would like to exit. Thus, allowing the delegated user to change passwords for student accounts.



      I have tested the code for the password change and it works without any issues.



      As soon as I try adding a while loop the code wont run.



      #Open powershell as Administrator
      Start-process Powershell -verb RunAs

      # Connect to the Domain Controller
      $session = New-PSSession -ComputerName "" -Credential (Get-Credential)
      Invoke-Command $session -Scriptblock Import-Module ActiveDirectory
      Import-PSSession -session $session -Module ActiveDirectory

      #verify that you're connectedto the Domain
      Get-ADDomainController -Filter * | Select-Object name

      #run Password Change
      $userid = Read-Host -Prompt 'Please enter the studnets login ID'
      $newPassword = Read-Host -Prompt 'Please enter the studnets new password'

      $run = 'yes'
      while ($run -eq 'yes')

      if (Get-ADUser -Filter SamAccountName -eq $userid)

      Set-ADAccountPassword $userid -Reset -NewPassword (ConvertTo-SecureString -Force -AsPlainText '$newPassword')
      Write - Host "$userid` password has now been changed to: $newPassword"

      else

      Write - Host "$userid` does not exist, please try again."

      $answer = Read-Host -Prompt 'Would you like to change another studnets password? [y









      share|improve this question
















      I'm trying to write a code in PowerShell that will loop till the user would like to exit. Thus, allowing the delegated user to change passwords for student accounts.



      I have tested the code for the password change and it works without any issues.



      As soon as I try adding a while loop the code wont run.



      #Open powershell as Administrator
      Start-process Powershell -verb RunAs

      # Connect to the Domain Controller
      $session = New-PSSession -ComputerName "" -Credential (Get-Credential)
      Invoke-Command $session -Scriptblock Import-Module ActiveDirectory
      Import-PSSession -session $session -Module ActiveDirectory

      #verify that you're connectedto the Domain
      Get-ADDomainController -Filter * | Select-Object name

      #run Password Change
      $userid = Read-Host -Prompt 'Please enter the studnets login ID'
      $newPassword = Read-Host -Prompt 'Please enter the studnets new password'

      $run = 'yes'
      while ($run -eq 'yes')

      if (Get-ADUser -Filter SamAccountName -eq $userid)

      Set-ADAccountPassword $userid -Reset -NewPassword (ConvertTo-SecureString -Force -AsPlainText '$newPassword')
      Write - Host "$userid` password has now been changed to: $newPassword"

      else

      Write - Host "$userid` does not exist, please try again."

      $answer = Read-Host -Prompt 'Would you like to change another studnets password? [y






      powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 3:13







      Brendan Harris

















      asked Mar 25 at 2:56









      Brendan HarrisBrendan Harris

      193




      193






















          1 Answer
          1






          active

          oldest

          votes


















          1














          PowerShell is not case sensitive by default / design. So, no need to check for that.



          Based on what you are after, you have potentially over engineered this item.



          I'd suggest changing this to a simple to a Do..Until.



          Clear-Host
          do

          "`n"
          $TargetUser = Read-Host -Prompt 'Enter a user SamAccountName'
          "Processing user $TargetUser"
          Get-ADUser -Identity $TargetUser
          "`n"
          $answer = Read-Host -Prompt 'Would you like to see another user? [y
          until ($answer -eq 'n')

          "You entered $answer. Finished processing routine."

          Enter a user SamAccountName: Administrator
          Process user Administrator


          ...
          Enabled : True
          GivenName :
          Name : Administrator
          ...
          SamAccountName : Administrator
          ...

          Would you like to see another user? [y|n]: y

          Enter a user SamAccountName: sqladmin
          Process user sqladmin

          ...
          Enabled : True
          GivenName : SqlAdmin
          Name : SqlAdmin ServiceAccount
          ...
          SamAccountName : sqladmin
          ...

          Would you like to see another user? [y|n]: n
          You entered n. Finished processing routine.


          Personally, if it were me doing this, I'd approach this a different way.



          1. Create file on a share that can be updated with user SamAccountName
            / ID's for target changes.

          2. Read in that file in the code.

          3. In the code, auto generate a password.

          4. Do whatever additional steps as needed in the code.

          Thus removing all the manual prompting labor.






          share|improve this answer

























            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%2f55330701%2fad-delegated-user-password-change%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            PowerShell is not case sensitive by default / design. So, no need to check for that.



            Based on what you are after, you have potentially over engineered this item.



            I'd suggest changing this to a simple to a Do..Until.



            Clear-Host
            do

            "`n"
            $TargetUser = Read-Host -Prompt 'Enter a user SamAccountName'
            "Processing user $TargetUser"
            Get-ADUser -Identity $TargetUser
            "`n"
            $answer = Read-Host -Prompt 'Would you like to see another user? [y
            until ($answer -eq 'n')

            "You entered $answer. Finished processing routine."

            Enter a user SamAccountName: Administrator
            Process user Administrator


            ...
            Enabled : True
            GivenName :
            Name : Administrator
            ...
            SamAccountName : Administrator
            ...

            Would you like to see another user? [y|n]: y

            Enter a user SamAccountName: sqladmin
            Process user sqladmin

            ...
            Enabled : True
            GivenName : SqlAdmin
            Name : SqlAdmin ServiceAccount
            ...
            SamAccountName : sqladmin
            ...

            Would you like to see another user? [y|n]: n
            You entered n. Finished processing routine.


            Personally, if it were me doing this, I'd approach this a different way.



            1. Create file on a share that can be updated with user SamAccountName
              / ID's for target changes.

            2. Read in that file in the code.

            3. In the code, auto generate a password.

            4. Do whatever additional steps as needed in the code.

            Thus removing all the manual prompting labor.






            share|improve this answer





























              1














              PowerShell is not case sensitive by default / design. So, no need to check for that.



              Based on what you are after, you have potentially over engineered this item.



              I'd suggest changing this to a simple to a Do..Until.



              Clear-Host
              do

              "`n"
              $TargetUser = Read-Host -Prompt 'Enter a user SamAccountName'
              "Processing user $TargetUser"
              Get-ADUser -Identity $TargetUser
              "`n"
              $answer = Read-Host -Prompt 'Would you like to see another user? [y
              until ($answer -eq 'n')

              "You entered $answer. Finished processing routine."

              Enter a user SamAccountName: Administrator
              Process user Administrator


              ...
              Enabled : True
              GivenName :
              Name : Administrator
              ...
              SamAccountName : Administrator
              ...

              Would you like to see another user? [y|n]: y

              Enter a user SamAccountName: sqladmin
              Process user sqladmin

              ...
              Enabled : True
              GivenName : SqlAdmin
              Name : SqlAdmin ServiceAccount
              ...
              SamAccountName : sqladmin
              ...

              Would you like to see another user? [y|n]: n
              You entered n. Finished processing routine.


              Personally, if it were me doing this, I'd approach this a different way.



              1. Create file on a share that can be updated with user SamAccountName
                / ID's for target changes.

              2. Read in that file in the code.

              3. In the code, auto generate a password.

              4. Do whatever additional steps as needed in the code.

              Thus removing all the manual prompting labor.






              share|improve this answer



























                1












                1








                1







                PowerShell is not case sensitive by default / design. So, no need to check for that.



                Based on what you are after, you have potentially over engineered this item.



                I'd suggest changing this to a simple to a Do..Until.



                Clear-Host
                do

                "`n"
                $TargetUser = Read-Host -Prompt 'Enter a user SamAccountName'
                "Processing user $TargetUser"
                Get-ADUser -Identity $TargetUser
                "`n"
                $answer = Read-Host -Prompt 'Would you like to see another user? [y
                until ($answer -eq 'n')

                "You entered $answer. Finished processing routine."

                Enter a user SamAccountName: Administrator
                Process user Administrator


                ...
                Enabled : True
                GivenName :
                Name : Administrator
                ...
                SamAccountName : Administrator
                ...

                Would you like to see another user? [y|n]: y

                Enter a user SamAccountName: sqladmin
                Process user sqladmin

                ...
                Enabled : True
                GivenName : SqlAdmin
                Name : SqlAdmin ServiceAccount
                ...
                SamAccountName : sqladmin
                ...

                Would you like to see another user? [y|n]: n
                You entered n. Finished processing routine.


                Personally, if it were me doing this, I'd approach this a different way.



                1. Create file on a share that can be updated with user SamAccountName
                  / ID's for target changes.

                2. Read in that file in the code.

                3. In the code, auto generate a password.

                4. Do whatever additional steps as needed in the code.

                Thus removing all the manual prompting labor.






                share|improve this answer















                PowerShell is not case sensitive by default / design. So, no need to check for that.



                Based on what you are after, you have potentially over engineered this item.



                I'd suggest changing this to a simple to a Do..Until.



                Clear-Host
                do

                "`n"
                $TargetUser = Read-Host -Prompt 'Enter a user SamAccountName'
                "Processing user $TargetUser"
                Get-ADUser -Identity $TargetUser
                "`n"
                $answer = Read-Host -Prompt 'Would you like to see another user? [y
                until ($answer -eq 'n')

                "You entered $answer. Finished processing routine."

                Enter a user SamAccountName: Administrator
                Process user Administrator


                ...
                Enabled : True
                GivenName :
                Name : Administrator
                ...
                SamAccountName : Administrator
                ...

                Would you like to see another user? [y|n]: y

                Enter a user SamAccountName: sqladmin
                Process user sqladmin

                ...
                Enabled : True
                GivenName : SqlAdmin
                Name : SqlAdmin ServiceAccount
                ...
                SamAccountName : sqladmin
                ...

                Would you like to see another user? [y|n]: n
                You entered n. Finished processing routine.


                Personally, if it were me doing this, I'd approach this a different way.



                1. Create file on a share that can be updated with user SamAccountName
                  / ID's for target changes.

                2. Read in that file in the code.

                3. In the code, auto generate a password.

                4. Do whatever additional steps as needed in the code.

                Thus removing all the manual prompting labor.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 3:35

























                answered Mar 25 at 3:18









                postanotepostanote

                4,8052411




                4,8052411





























                    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%2f55330701%2fad-delegated-user-password-change%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현