#skype4B/Lync #powershell Script: Compare User Policy (Update v1.10)

This revised version of Compare-Skype4BUserPolicy adds the option to include items that hold the same values. It is one of the many PowerShell functions/utilities in my personal script toolbox repository designed to help simplify the management and administration of just about any Lync / Skype for Business Server environments.

Have fun!

################################################################################
# Copyright (c) 201x-2017 leedesmond.com
# All Rights Reserved. Use at your own risk and responsibility.
# Compare-Skype4BUserPolicy.ps1
# Version 1.10
#
# USAGE:
# Compare-Skype4BUserPolicy $u1 $u2 -IncludeEqual
# Compare-Skype4BUserPolicy $u1 $u2 -DistinctObject -IncludeEqual
#
# INPUT:
# Identity of users A and B to compare user policies. Use the -DistinctObject
# switch to segregate output into unique objects.
#
# OUTPUT:
# Returns a custom object listing the different and/or same attributes (policies)
# of the compared user accounts. An array of unique objects is returned with the
# -DistinctObject switch.
#
#requires -version 3.0
################################################################################
#
function Compare-Skype4BUserPolicy()
{
param(
[string]$userRef = $null,
[string]$userTC1 = $null,
[switch]$DistinctObject,
[switch]$IncludeEqual
)
if ( -not ($userRef) -or -not ($userTC1) ) {
"Usage: Compare-Skype4BUserPolicy ID1 ID2 [`$DistinctObject|`$IncludeEqual]
";
return;
}
#
if (-not (Get-Module -ListAvailable -Name SkypeForBusiness)) {
Import-Module -Name SkypeForBusiness;
}
#
$mp = (Get-CsUser $userRef), (Get-CsUser $userTC1);
$csusernp = (Get-CsUser $userRef) | Select-Object -Property * |
Get-Member -MemberType NoteProperty;
#
$list = New-Object 'System.Collections.Generic.List[System.Object]'
$mp | % {
$item = $_;
$obj = New-Object PsObject;
$csusernp | % {
$obj | Add-Member -MemberType NoteProperty -Name $($PSItem.Name) `
-Value $item.$($PSItem.Name);
}
$list.Add($obj);
}
$exclProp = "element,anchor,*Sid,Guid";
#
$exclProp = $exclProp -split ",";
$list1 = $list.ToArray() | Select-Object -Property * -ExcludeProperty $exclProp;
#
$objleft = $csusernp.Name | % { "{$_}"+$list1[0].$_; }
$objright = $csusernp.Name | % { "{$_}"+$list1[1].$_; }
#
if ($IncludeEqual) {
$diff1 = Compare-Object $objleft $objright -IncludeEqual;
} else {
$diff1 = Compare-Object $objleft $objright;
}
#
$rx = [regex]"{(.+)}(.+)";
$objl = New-Object PSObject;
$objr = New-Object PSObject;
$diff1 | % {
$io = $PsItem.InputObject;
$si = $PsItem.SideIndicator;
$m1 = $m2 = "";
if ($io -match $rx) {
$m1 = $matches[1];
$m2 = $matches[2];
}
else #null or blank values
{
$m1 = $io.SubString(1,$io.IndexOf("}")-1);
$m2 = "";
}
#
if ($si -eq "<=") {
$objl | Add-Member -MemberType NoteProperty -Name $m1 -Value $m2;
} elseif ($si -eq "=>") {
$objr | Add-Member -MemberType NoteProperty -Name $m1 -Value $m2;
} else {
$objl | Add-Member -MemberType NoteProperty -Name "=$($m1)" -Value $m2;
$objr | Add-Member -MemberType NoteProperty -Name "=$($m1)" -Value $m2;
}
#
} #diff1 | % {
#
$rv = $objl, $objr;
if ($DistinctObject) { Write-Output $rv; }
else {
$onp = $objl | Get-Member -MemberType NoteProperty;
#
$tbl = New-Object PsObject;
$onp.Name | % {
$tbl | Add-Member -MemberType NoteProperty -Name $PSItem -Value $rv.$PsItem;
}
Write-Output $tbl;
}
} #Compare-Skype4BUserPolicy()
################################################################################

Leave a Reply