Category Archives: Microsoft

Move OCS Users in an OU to Lync 2010

I used this script to migrate OCS 2007 R2 users to Lync 2010. On the contract I was working we had 6000 users to migrate across EMEA. Users were split into OUs for their Country, so we did this each night country by country.

Import-Module Lync
Get-CSUser -OU "OU=UK,DC=domain,DC=local" | %{
$User = $_
Try {
Move-CsLegacyUser -Target "lync-pool-name" -EA STOP
}
Catch{
Echo $User $_.exception.Message
}
} | Out-File C:\Lynclog.txt
Facebooktwittergoogle_pluslinkedinby feather

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