Category Archives: Powershell

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 »

Set Out of office for multiple users

If you need to set the out of office for multiple users you can use a powershell script Set-MailboxAutoReplyConfiguration ALIAS -AutoReplyState scheduled -StartTime “07/12/2013 14:05:00” -EndTime “08/05/2013 08:00:00” -ExternalAudience all -InternalMessage $oof -ExternalMessage $oof where the variable $oof is a predefined message. $oof = “I’m not in the office currently” Here I’ll give a more… Read More »