'How to continue using a powershell script after it finished
I don't know much about scripting at all, but want to help out my lead with something. I'm trying to create a script that will ask for a username and it will return when their password will expire in AD. I also want to continue inputting usernames after it has finished in case there are multiple users I need to check. Below is the script I have so far.
$User = Read-Host "Username?"
Get-ADUser $User -Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |
Select-Object -Property "Displayname", @{Name = "ExpiryDate"; Expression = {[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
I was looking into doing loops, but I do not know how to write it out. Any help would be appreciated. Thanks.
Solution 1:[1]
You could also use a while loop
while ($true) {
$User = Read-Host "Username?"
Get-ADUser $User -Properties "DisplayName","msDS-UserPasswordExpiryTimeComputed" | Select-Object -Property "Displayname", @{Name = "ExpiryDate"; Expression = {[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
if ($User -eq "q!") {
break
}
}
To quit the while loop enter "q!" in place of a user.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lakshaya U. |
