Author Archives: dean132

Get ActiveSync Details for users in an OU

The below script will show ActiveSync details for users in an OU, this script also only reports devices that have synced after a specified date.


Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

Get-Mailbox -ResultSize:Unlimited -OrganizationalUnit domain.local/OU | ? {$_.Organizationalunit -eq "domain.local/OU "} | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity} | Where {$_.LastSuccessSync -gt '01/01/2014'} | ft -AutoSize Identity,DeviceType,DeviceID,DeviceModel,LastSuccessSync
Facebooktwittergoogle_pluslinkedinby feather

Get Users AD Account from EMail Address

This script will take a list of email address and return the users AD info, I have enabled View Entire Forest, in case your are in a multi domain environment.

Import-Module ActiveDirectory
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$AdminSessionADSettings.ViewEntireForest = $true
Get-Content C:\EmailList.txt | Get-Mailbox | FT SamAccountName,Alias,PrimarySMTP
Facebooktwittergoogle_pluslinkedinby feather

List all Sites and Subnets in AD

This script will export a list of all Site and Subnets and the domain controllers in them.

[cmdletbinding()]
 param()

$Sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
$obj = @()
foreach ($Site in $Sites) {

  $obj += New-Object -Type PSObject -Property (
   @{
    "SiteName"  = $site.Name
    "SubNets"  = $site.Subnets  -Join ";"
    "Servers"  = $Site.Servers  -Join ";"
   }
  )
 }
$obj | Export-Csv 'C:\sites.csv' -NoType
Facebooktwittergoogle_pluslinkedinby feather

Post Migration Scripts for O365 – Part 2 Set Retention Policy and Retain Deleted items from a csv file

When migrating users to O365, you may need to set a group of users or specific users Item Retention and Deleted Item retention policies. If you have a list of users who need specific settings you can run the following command against the list to only apply the desired settings to those users. You will need to connect to O365 to run these scripts for O365 Users.

### This script will list all users in a csv file who have a Deleted Items retention setting if 14 Days and change it to 30 Days.

Import-CSV "C:\UKUsers.csv" | %{Get-Mailbox -identity $_.UserPrincipleName | where {$_.retaindeleteditemsfor -eq "14.00:00:00"} | Set-Mailbox -RetainDeletedItemsFor "30.00:00:00"}
 

### This script will search for users in a csv file who have a particular Retention Policy assigned and set it to another policy.

Import-CSV "C:\UKUsers.csv" | %{Get-Mailbox -identity $_.UserPrincipleName | where{$_.RetentionPolicy -eq "Incorrect Policy Name"} | Set-Mailbox -RetentionPolicy "Correct Policy Name"}
Facebooktwittergoogle_pluslinkedinby feather

Post Migration Scripts for O365 – Part 1 Set usage location and Enable License from a csv file

When you are migrating users to O365 there may be a requirement to run post migration scripts, for setting the users location, and enabling licenses. You may be performing the migrations using a csv, and users may be in different locations, so you cannot just run the commands against the entire organisation. The csv contains a list of User UPNs.

### First we must find out our License SKU to apply

Connect-MsolService

Get-MsolAccountSku

### Set a users location to GB

Connect-MsolService

Import-CSV "C:\UKUsers.csv" | %{Get-MSolUser -SearchString $_.UserPrincipleName | Set-MsolUser -UsageLocation GB | ft UserPrincipalName,DisplayName,IsLicensed,UsageLocation}

### Set users license, also disable Plans that are not needed, in our case we are just using Exchange Online so we disable everything else

Connect-MsolService

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId companyname:ENTERPRISEPACK -DisabledPlans SHAREPOINTENTERPRISE,MCOSTANDARD,OFFICESUBSCRIPTION,YAMMER_ENTERPRISE,SHAREPOINTWAC,RMS_S_ENTERPRISE

Import-CSV "C:\UKUsers.csv" | %{Set-MsolUserLicense $_.UserPrincipleName –AddLicenses companyname:ENTERPRISEPACK –LicenseOptions $LicenseOptions}

Facebooktwittergoogle_pluslinkedinby feather