Category : Programming

Using Powershell with Active Directory Hint: Enable View > Advanced Features in the AD GUI to view all the properties a user has. Import the AD Module Import-Module ActiveDirectory Add a new AD User #New-ADUser -Name “<Full Name>” -GivenName “<Firstname>” -Surname “<Lastname>” -SamAccountName “<shortname>” -UserPrincipalName “<email@address.tld>” -Path “OU=Administration,OU=Staff,OU=STARWARS,DC=starwars,DC=com” -AccountPassword(ConvertTo-SecureString “<Password>” -AsPlainText -force) -Enabled $true New-ADUser ..

Read more

Functions Define a function function myFunction { param( #define parameters $MyParameter ) # Do some stuff Write-Host “You set MyParameter to” $MyParameter } myFunction -MyParameter 10 Note: above function prints ‘You set MyParameter to 10’ Cmdlet Bindings If the required parameter is not set when calling, the function will might fail. You can avoid this ..

Read more

Conditions Terrinaries -eq Equal To -ne Not Equal To -le Less than or Equal To -lt Less than -ge Greater than or Equal To -gt Greater than Boolians -and And: ($x -eq $y -and $i -ne $j) -or Or: ($x -eq $y -or $i -ne $j) -xor: ($x -eq $y -xor $i -ne $j) -not ..

Read more

Powershell Variables Variables Variable Objects All variables are Objects   Variable declaration: $VarName Note: These are NOT case sensitive! $MyVar is the same as $myvar Static variables (aka read-only constants): $true (True, 1) $false (False, 0) Note: You cannot assign variable to to True or False. Use their variable names. Get Variable type Note: Here ..

Read more