#skype4b #powershell Compare (Any) Lync/Skype Policy

Compare-SfbAnyPolicy 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.

Enjoy!

################################################################################
# Copyright (c) 201x-2017 leedesmond.com
# All Rights Reserved. Use at your own risk and responsibility.
# Compare-SfbAnyPolicy.ps1
# Version 1.00
#
################################################################################
#
function Compare-SfbAnyPolicy
{
param($csp = $null, [switch]$includeNullFields)

if (-not $csp) {
“Usage: Compare-SfbAnyPolicy (Get-Cs… | Select-Object -Property *)”
“e.g.”
“`t`$out = Compare-SfbAnyPolicy (Get-CsClientPolicy | Select-Object -Property *)”
“`t`$out | ogv”
“`t`$out | Export-Csv -Path CsClientPolicy.csv -NoTypeInformation -UseCulture -Encoding UTF8”
return;
}

$csprop = ($csp[0] | gm -MemberType NoteProperty).name;

$np = New-Object System.Collections.ArrayList;
[void]$np.AddRange($csprop);

$list = New-Object System.Collections.ArrayList;
$csp | % {
$item = $_;
$csprop | % `
-Begin {
$obj = New-Object psobject;
$obj | Add-Member -MemberType NoteProperty -Name Identity -Value $csp[0].Identity;
} `
-Process {
if ($PsItem -notmatch “anchor|element”) {
$obj | Add-Member -MemberType NoteProperty -Name $PsItem -Value $($item.$PsItem) -Force;
}
} `
-End {
[void]$list.Add($obj);
}
}

if ($includeNullFields) { $list; }
else {
$np | ? { $list.$PsItem |
#first filter out null fields
? { $PsItem -eq $null } } |
% {
$n = $PSItem;
$allnull = $true;
$list | % { if ($_.$n -ne $null) { $allnull = $false; } }

#remove the entire field if all policies have null/empty entries
if ($allnull) {
$list | % { $_.PsObject.Members.Remove($n); }
}
}
Write-Output $list;
}

} #Compare-SfbAnyPolicy()

Bookmark the permalink.

Leave a Reply