Monthly Archives: November 2018

Update AD users from CSV

Create a CSV file with relevant data i.e. sAMAccountName,postalCode,givenName,sn user.name,444444,user,name Then import and run piping results to a csv.  Adapt the CSV and Set-AdUser sections to do what job you need. $data = Import-CSV -Path .\data.csv $data | ForEach-Object { $user = Get-ADUser -Filter “sAMAccountName -like ‘*$($_.sAMAccountName)*’” -Properties st,postalCode Set-ADUser -identity $user.sAMAccountName -PostalCode $_.postalCode }… Read More »

Licensing Office 365 via script

Powershell script that can be adapted to license Office 365 with various service plans. Import-Module MSOnline  Connect-MsolService -Credential $Credentials $SessionParams = @{     ConfigurationName = “Microsoft.Exchange”     ConnectionUri = “https://outlook.office365.com/powershell-liveid/”     Credential = $Credentials     Authentication = “Basic”     AllowRedirection = $true}   $Session = New-PSSession @SessionParams Import-PSSession -Session $Session -DisableNameChecking:$true -AllowClobber:$true | Out-Null #Get… Read More »

Powershell script to delete inactive computer accounts.

A nice quick script to get machines that have not logged on to the network in over x days, move to another OU and disable.   $d = [DateTime]::Today.AddDays(-365) $todisable = Get-ADComputer -Filter ‘PasswordLastSet -le $d’ -Properties PasswordLastSet | Where-Object {$_.DistinguishedName -notlike “*OU=Disabled*”} $todisable | %{Move-ADObject -Identity $_.DistinguishedName -TargetPath “OU=Disabled,OU=Computers,DC=domain,DC=local” | FT Name,PasswordLastSet} $todisable |… Read More »