#Skype4B/Lync Script: Compare User Policy

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

—–
Compare-Skype4BUserPolicy 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.00
#
# USAGE:
# Compare-Skype4BUserPolicy $u1 $u2
# Compare-Skype4BUserPolicy $u1 $u2 -DistinctObject
#
# 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 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,
[string]$userTC1,
[switch]$DistinctObject
)
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].$_; }

$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;
} else {
$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