Skip to content

Instantly share code, notes, and snippets.

@Just-Insane
Created May 23, 2018 02:19
Show Gist options
  • Save Just-Insane/0bca2d4358abcdf14c1fde81e74077af to your computer and use it in GitHub Desktop.
Save Just-Insane/0bca2d4358abcdf14c1fde81e74077af to your computer and use it in GitHub Desktop.
Powershell user info
#Variables
Write-Host "What is the Username?" -ForegroundColor Yellow
$Username = Read-Host "Username: "
$getGroups = $false
function UnlockAccount {
if ($_.LockedOut -eq $true) {
Write-Host "Account is locked, unlock?" -ForegroundColor Red
$Readhost = Read-Host "( y / n ) "
Switch ($Readhost) {
Y {Write-Host "Yes, unlock the account" -NoNewline; $unlock=$true}
N {Write-Host "No, do not unlock the account" -NoNewline; $unlock=$false}
Default {Write-Host "Default, do not unlock the account" -NoNewline; $unlock=$false}
}
}
if ($unlock -eq $true) {
Unlock-ADAccount -Identity $Username
}
}
function Set-Password {
Write-Host "What should the password be?"
$Password = Read-Host "Password"
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
Set-ADAccountPassword -Identity $Username -Reset -NewPassword $SecurePassword
}
function UserAccountInfo {
Get-ADUser -Identity $Username -Properties *, "msDS-UserPasswordExpiryTimeComputed", "accountExpires" |
Select-Object @{Label = "First Name";Expression = {$_.GivenName}},
@{Label = "Last Name";Expression = {$_.Surname}},
@{Label = "Display Name";Expression = {$_.DisplayName}},
@{Label = "Logon Name";Expression = {$_.sAMAccountName + "`n"}},
@{Label = "Description";Expression = {$_.Description}},
@{Label = "Department";Expression = {$_.Department}},
@{Label = "Home Directory";Expression = {$_.HomeDirectory}},
@{Label = "Distinguished Name";Expression = {$_.DistinguishedName}},
@{Label = "Email";Expression = {$_.Mail}},
@{Label = "Extension Attribute 2";Expression = {$_.extensionAttribute2 + "`n"}},
@{Label = "Account Status";Expression = {
if ($_.Enabled -eq 'TRUE') {
'Enabled'
}
Else {
'Disabled'
}}},
@{Label = "Account Expires";Expression = {[datetime]::FromFileTime($_."accountExpires")}},
@{Label = "Last Log-On Date";Expression = {$_.lastlogondate}},
@{Label = "Password Last Set";Expression = {$_.PasswordLastSet}},
@{Label = "Password Expired";Expression = {$_.PasswordExpired}},
@{Label = "Password Expiry Date";Expression = {[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}},
@{Label = "Account Locked";Expression = {
if ($_.LockedOut -eq $false) {
"Not Locked"
}
Else {
[datetime]::FromFileTime($_.lockoutTime)
UnlockAccount -Username = $Username
}}},
@{Label = "Last Bad Password Attempt";Expression = {$_.LastBadPasswordAttempt}}
}
function UserGroupInfo {
Get-ADPrincipalGroupMembership $Username |
Select-Object name |
Format-Table
}
UserAccountInfo -Username = $Username
Write-Host "Reset Password" -ForegroundColor Yellow
$Readhost = Read-Host "( y / n ) "
Switch ($Readhost) {
Y {Write-Host "Yes, reset users password"; $setPass=$true}
N {Write-Host "No, do not reset users password"; $setPass=$false}
Default {Write-Host "Default, do not reset users password"; $setPass=$false}
}
if ($setPass -eq $true) {
Set-Password -Username = $Username
}
Write-Host "Get User's Groups" -ForegroundColor Yellow
$Readhost = Read-Host "( y / n ) "
Switch ($Readhost) {
Y {Write-Host "Yes, get User's groups" -NoNewline; $getGroups=$true}
N {Write-Host "No, do not get User's groups" -NoNewline; $getGroups=$false}
Default {Write-Host "Default, do not get User's groups" -NoNewline; $getGroups=$false}
}
if ($getGroups -eq $true) {
UserGroupInfo -Username = $Username
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment