Pages

8/26/2022

Update AD Username Casing

 We all know that usernames in Active Directory are not case sensitive, for the most part everywhere that is the case. But I had a customer who wanted to ensure all the usernames were lowercase for reasons we shall not ask. 

Below is just one example of how you can accomplish this in PowerShell


$InformationPreference = 'Continue'

$users = Get-ADUser -Filter * -SearchBase "OU=MSHELDON,DC=T4EDEV,DC=local"

foreach($user in $users) {

    try {

            $user | Set-ADUser -Replace @{ sAMAccountName = $user.SamAccountName.ToLower() }

            Write-Information "Updated user [$($user.SamAccountName)]"

    } catch {

        Write-Warning "Failed to update user [$($user.SamAccountName)]"

    }

}

7/25/2022

Generate Self-Signed Certificate with PowerShell

It's been a long time, but I'm back. Here is a sample script to generate a self-signed certificate. This was helpful for building API access to Adobe Cloud User Management API


 ### Create Self-Signed Certificate (only works Windows 8.1, 10, Server 2016+ ###

$Name           = "MyCert"
$ExportPath     = "C:\Data"           # Path to export cert
$Password       = "MySecretPassword"  # Passphrase on cert
$CertTtlMonths  = 24                  # Lifespan of the cert in months
 
$SecurePwd      = ConvertTo-SecureString -String $Password -Force -AsPlainText
$Certificate    = New-SelfSignedCertificate -DnsName $Name -CertStoreLocation "cert:\LocalMachine\My" -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -HashAlgorithm "SHA256" -NotAfter (Get-Date).AddYears($CertTtlMonths)
Get-ChildItem -Path ("cert:\localMachine\My\" + $Certificate[0].Thumbprint ) | Export-PfxCertificate -FilePath "$ExportPath\MyCert.pfx" -Password $SecurePwd
  
  
### Export Public Key (Required Server 2016+) ###
Export-Certificate -FilePath "$ExportPath\MyCert.cer" -Cert $Certificate -Type CERT -NoClobber
CertUtil -Encode "$ExportPath\MyCert.cer" "$ExportPath\MyCertB64.crt"