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;
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
add a comment |
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
add a comment |
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
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
powershell
edited Mar 25 at 3:13
Brendan Harris
asked Mar 25 at 2:56
Brendan HarrisBrendan Harris
193
193
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
- Create file on a share that can be updated with user SamAccountName
/ ID's for target changes. - Read in that file in the code.
- In the code, auto generate a password.
- Do whatever additional steps as needed in the code.
Thus removing all the manual prompting labor.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
- Create file on a share that can be updated with user SamAccountName
/ ID's for target changes. - Read in that file in the code.
- In the code, auto generate a password.
- Do whatever additional steps as needed in the code.
Thus removing all the manual prompting labor.
add a comment |
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.
- Create file on a share that can be updated with user SamAccountName
/ ID's for target changes. - Read in that file in the code.
- In the code, auto generate a password.
- Do whatever additional steps as needed in the code.
Thus removing all the manual prompting labor.
add a comment |
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.
- Create file on a share that can be updated with user SamAccountName
/ ID's for target changes. - Read in that file in the code.
- In the code, auto generate a password.
- Do whatever additional steps as needed in the code.
Thus removing all the manual prompting labor.
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.
- Create file on a share that can be updated with user SamAccountName
/ ID's for target changes. - Read in that file in the code.
- In the code, auto generate a password.
- Do whatever additional steps as needed in the code.
Thus removing all the manual prompting labor.
edited Mar 25 at 3:35
answered Mar 25 at 3:18
postanotepostanote
4,8052411
4,8052411
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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