Powershell Master Cheatsheet
Get LAPS Password
Get-LapsADPassword mut7gpc202 -AsPlainTextHide a user from the Global Address List
Set-ADUser paulie -Replace @{msExchHideFromAddressLists=$true}
Unhide a user from the Global Address List
Set-ADUser paulie -Replace @{msExchHideFromAddressLists=$false}
Return Deleted Users From Azure AD
connect-msolservice
Get-MsolUser -ReturnDeletedUsersRemove Object From Azure Recycle Bin
Remove-MsolUser -UserPrincipalName user3453@mutschlerhome.com -RemoveFromRecycleBin
Set Azure User Immutable ID
#$credential = Get-Credential
#Connect-MsolService -Credential $credential
$ADUser = "user"
$365User = "user@mutschlerhome.com"
$guid =(Get-ADUser $ADUser).Objectguid
$immutableID=[system.convert]::ToBase64String($guid.tobytearray())
Set-MsolUser -UserPrincipalName "$365User" -ImmutableId $immutableID
Set Azure Group mS-DS-ConsistencyGUID ID
Set-ADGroup -Identity 'CN=Service Accounts - Deny Interactive Logon,OU=To Move,DC=corp,DC=mutschlerhome,DC=com' -Replace @{'mS-DS-ConsistencyGuid'='2155c959-564f-405e-bea9-395632aba1d1'} -ErrorAction Stop
List all users hidden from the GAL
Get-ADUser -Filter {msExchHideFromAddressLists -eq "TRUE"} |Select-Object UserPrincipalName
Remove Object From Active Directory Recycle Bin
-
Run Powershell as an
admin - Check first to verify you only get the user you want from the following command.
Get-ADObject -Filter 'isDeleted -eq $True -and Name -like "*username*"' -IncludeDeletedObjects
- Once you verified the only result is the user you want to delete permanently, run the following command.
Get-ADObject -Filter 'isDeleted -eq $True -and Name -like "*username*"' -IncludeDeletedObjects | Remove-ADObject
AD Health Check With Email
Active Directory List Users In Groups
$Members = @()
$domains = (Get-ADForest).domains
foreach ($domain in $domains) {
$Groups = Get-ADGroup -Filter { Name -like "Enterprise Admins" } -Server $domain | Get-ADGroupMember -Server $domain
$Members += $Groups
}
$Members | Export-CSV -Path C:\Temp\Admins.csv -NoTypeInformationCustom Intune Detection Script
Disconnect Disconnected Users
$pc = qwinsta /server:dcwipvmhsj001 | select-string "Disc" | select-string -notmatch "services"
if ($pc)
{
$pc| % {
logoff ($_.tostring() -split ' +')[2] /server:SERVERNAME
}
}
Distribution List Modification
Export Local Group Membership
net localgroup “Administrators” > C:\Servers.txt
Get CPU and RAM Usage
Get Drive/Folder Owner
GET-ACL “$Path”| select path, Owner -expand access | select @{n=”Path”;e={$_.Path.replace(“Microsoft.PowerShell.Core\FileSystem::”,””)}}, Owner, IdentityReference, FileSystemRights, AccessControlType, IsInherited
