Skip to content

Instantly share code, notes, and snippets.

param($AccountName)
$adUser = Get-AdUser $AccountName
$immutableID = [system.convert]::ToBase64String($adUser.ObjectGuid.tobytearray())
return $immutableID
param($dll, $namespace, $class, $method, $args)
Add-Type -Path $dll
[$namespace.$class]::$method($args)
@wim-beck
wim-beck / getPwdExpiration.ps1
Created November 7, 2019 08:18
Get the password expiration date for an AD user
param($AccountName)
Get-ADUser $AccountName -Properties displayname,msDS-UserPasswordExpiryTimeComputed | Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
@wim-beck
wim-beck / generatePwd.cs
Created August 30, 2018 11:53
Generate password C#
// Assembly: System.Web
using System.Web.Security;
Membership.GeneratePassword(30, 7);
# Source: http://virot.eu/get-the-sid-of-all-domains-in-a-forest/
Import-Module ActiveDirectory
(Get-ADForest).Domains| %{Get-ADDomain -Server $_}|select name, domainsid
@wim-beck
wim-beck / convertBase64ToPicture.ps1
Created May 19, 2017 10:08
Convert base64 to picture
param($textImg, $destinationImg)
$base64 = Get-Content $textImg
$bytes = [Convert]::FromBase64String($base64)
[IO.File]::WriteAllBytes($destinationImg, $bytes)
@wim-beck
wim-beck / runas.ps1
Last active March 24, 2017 16:59
Start powershell session as other user
# Start powershell session as other user
Start-Process PowerShell -Credential "Domain\username"
# Start powershell session as local admin
Start-Process PowerShell -Verb RunAs
@wim-beck
wim-beck / getGroups.ps1
Last active March 2, 2017 08:16
Get recursive group memberships
dsget user "CN=Mike Danseglio,CN=users,dc=ms,dc=tld" -memberof -expand
@wim-beck
wim-beck / getSystemAutomationDll.ps1
Last active March 2, 2017 08:12
Copy System.Management.Automation.dll to current directory
# Copy the current version of System.Management.Automation.dll to current directory
Copy ([PSObject].Assembly.Location) .
@wim-beck
wim-beck / resetPwd.ps1
Last active March 15, 2021 02:03
Reset AD password
param($AccountName)
# Reset a pwd, requires reset pwd rights on the obj:
Set-AdAccountPassword -Identity $AccountName -Reset -NewPassword (Read-Host -asSecureString "Enter the new password")
# Change a pwd, knowing the current password
Set-AdAccountPassword -Identity $AccountName -OldPassword (Read-Host -asSecureString "Enter the current password") -NewPassword (Read-Host -asSecureString "Enter the new password")