Random Password Generator

Define the password length and you’ll get a secure, randomly generated password.

1
2
$pwdLength = 15
$rngPWD = ([char[]]([char]33..[char]95) + ([char[]]([char]97..[char]126)) + 0..9 | sort {Get-Random})[0..$pwdLength] -join ''

If you need to use this for Active Directory user creation, you can convert the string to a securestring and use it like so:

1
2
$regPWDsec =  ConvertTo-SecureString $rngPWD -AsPlainText -Force
New-ADUser -Server 'blah.blah' -Path "OU=Blah,DC=blah,DC=blah" -AccountPassword $rngPWDsec -<all other defined parameters>

Add or Remove a single forest user to a group in all child domains

1
2
3
4
5
6
7
8
9
$user = Get-ADUser 'myusername' -Server 'forestdomain.com'
#==============================================================
$domains = Get-ADForest -Server 'rootdomain.com'
ForEach ($domain in $domains.Domains) {    
    $Group = Get-ADGroup -Identity 'Account Operators' -Server $domain
    # Uncomment the command below needed to add or remove
    #Add-ADGroupMember -Identity $Group -Member $user -Server $domain
    #Remove-ADGroupMember -Identity $Group -Member $user -Server $domain
}