4 September 2013

Show Assigned Users, Numbers and Policies in html

This one is a beauty!
My customer simply fires the Assigned_numbers.ps1 and gets an HTML file they can use to quickly spot DDI's, Policies etc. Since its HTML a ctrl-F assist nicely to find users and numbers

Original Script created by
Lasse Nordvik Wedø at http://tech.rundtomrundt.com/<#
.Synopsis
   A script to list all used numbers in a Lync deployment
.DESCRIPTION
    A script to list all used numbers in a Lync deployment
    Created by Lasse Nordvik Wedø

    V 1.1 - April 2012 - Added a function to count the number of users as well
    V 1.2 - June 2012 - Added a function to count and the number of users not enabled for EVas well
    V 1.3 - March 2013 - BugFIX + changing folder and filepath to a static value. Run this script without interaction.
    V1.3.1 -  Slightly Modified for my own use..by ME
                 Added additional columns to quickly see assigned policies
.EXAMPLE
   Assigned_numbers.ps1
#>



<#
 Setting folder, file and finding date
#>

$filepath = "c:\Lynctools\"
$date = "{0:yyyy_MM_dd-HH_mm}" -f (get-date)
$file = $filepath + "Assigned_numbers_" + $date + ".htm"
New-Item $filepath -type directory -force -Verbose
import-module lync

<#
 Creating a style for the htm output, coulors and sizes may be adjusted as fit.
 Building HTML Construct for $file
 the "out-file" simply writes whatever is in between the " " into the file.
#>

"<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>" | Out-File $file
"<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;>" | Out-File $file -append
"<head>" | Out-File $file -append
"<title>Assigned Users</title>" | Out-File $file -append
"<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;>" | Out-File $file -append
"<meta name=&quot;author&quot; content=&quot;Lasse Nordvik Wedø &quot;>" | Out-File $file -append
"<meta name=&quot;copyright&quot; content=&quot;Lasse Nordvik Wedø &quot;>" | Out-File $file -append
"<!--This is a documentation done based on a script by Lasse Nordvik Wedø at Datametrix, all rights reserved -->" | Out-File $file -append
"<style>BODY{background-color:#afcdd7;font-family:Arial;}TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}TH{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#5f9baf}TD{width:200px;border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#cfe1e7}" | Out-File $file -append
"</style>" | Out-File $file -append
"</head>" | Out-File $file -append
"<body>" | Out-File $file -append

<#
 Counting the number of users enabled for Lync
#>

[system.Console]::ForegroundColor = [System.ConsoleColor]::Gray
write-host "Fetching users enabled of Lync"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($sipaddress in (get-csuser -filter {LineURI -eq $Null})) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

<#first creating a header#>
"<H2>Lync Users</H2>" | Out-File $file -append
"<H6>Version 1.4, Adapted for Lexel - by PB</H6>" | Out-File $file -append
"<H3>There are $Showcounter users enabled for Lync without a lineURI</H3>" | Out-File $file -append
<#writing result#>
Get-CsUser -Filter {LineURI -eq $Null} | sort -Property sipaddress | Select-Object Name,sipaddress,VoicePOlicy,ConferencePolicy,LocationPolicy | ConvertTo-HTML | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

<#
Counting the number of users with a lineURI and listing them
#>

[system.Console]::ForegroundColor = [System.ConsoleColor]::Gray
write-host "Fetching users with LineURI"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($lineuri in (get-csuser -filter {LineURI -ne $Null})) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter users with a Primary LineURI</H3>" | Out-File $file -append
Get-CsUser -Filter {LineURI -ne $Null} | sort -Property lineuri | Select-Object LineURI,Name,sipaddress,VoicePOlicy,ConferencingPolicy,LocationPolicy | ConvertTo-HTML | Out-File $file -append

# Cleaning up the results
$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

<#
Counting the number of users with a Private LineURI and listing them
#>

write-host "Fetching users with a private line"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($privateline in (get-csuser -Filter {privateline -ne $Null})) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter users with a Private Line</H3>" | Out-File $file -append
Get-CsUser -Filter {privateline -ne $Null} | sort -Property privateline | Select-Object privateline,Name,sipaddress,VoicePolicy,ConferencingPolicy,LocationPolicy | ConvertTo-HTML -fragment | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

#<#
#Counting the number of analog devices and listing them
#>

#write-host "Fetching analog devices"
#$Showcounter = 0
#function countmy-users {
#$counting = 0
#foreach ($LineURI in Get-CsAnalogDevice) {
#$counting++
#}
#write-output $counting
#}
#$Showcounter += countmy-users

#"<H3>There are $Showcounter Analog Devices</H3>" | Out-File $file -append
#Get-CsAnalogDevice -Filter {LineURI -ne $Null}  | Sort -property lineuri | Select-Object lineuri,displayname,LocationPolicy   | ConvertTo-HTML -fragment | Out-File $file -append

#$Showcounter = $NULL
#$counting = $NULL
#$Showcounter = $NULL

<#
Counting the number of Common Area Phones and listing them
#>

write-host "Fetching common area phones"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($LineURI in Get-CsCommonAreaPhone) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter Common Area Phones</H3>" | Out-File $file -append
Get-CsCommonAreaPhone -Filter {LineURI -ne $Null}   | sort -property lineuri | Select-object lineuri, displaynumber, displayname,ClientPolicy  | ConvertTo-HTML -fragment | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

<#
Counting the number of RGS workflows and listing them
#>

write-host "Fetching RGS workflows"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($LineURI in Get-CsRgsWorkflow) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter RGS Workflows with a LineURI</H3>" | Out-File $file -append
Get-CsRgsWorkflow | sort -Property lineuri | Select-object lineuri,displaynumber,name,active | ConvertTo-HTML -fragment | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

<#
Counting the number of voice conference numbers and listing them
#>

write-host "Fetching voice conference numbers"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($LineURI in Get-CsDialInConferencingAccessNumber) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter Dialin Access numbers</H3>" | Out-File $file -append
Get-CsDialInConferencingAccessNumber -Filter {LineURI -ne $Null} | sort -Property lineuri | Select-object lineuri,displayname | ConvertTo-HTML -fragment | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

<#
Counting the number of Exchange objects and listing them
#>

write-host "Fetching voice Exchange objects"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($LineURI in Get-CsExUmContact) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter Exchange objects</H3>" | Out-File $file -append
Get-CsExUmContact -Filter {LineURI -ne $Null} | sort -Property lineuri | Select-object Lineuri,displayname,displayuri | ConvertTo-HTML -fragment | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

<#
Counting the number of trusted application points and listing them
#>

write-host "Fetching voice trusted application points"
$Showcounter = 0
function countmy-users {
$counting = 0
foreach ($LineURI in Get-CsTrustedApplicationEndpoint) {
$counting++
}
write-output $counting
}
$Showcounter += countmy-users

"<H3>There are $Showcounter trusted apllication endpoints, below are those with a LineURI</H3>" | Out-File $file -append
Get-CsTrustedApplicationEndpoint -Filter {LineURI -ne $Null} | sort -Property lineuri | Select-object -Property lineuri, displayname, displaynumber| ConvertTo-HTML -fragment | Out-File $file -append

$Showcounter = $NULL
$counting = $NULL
$Showcounter = $NULL

[system.Console]::ForegroundColor = [System.ConsoleColor]::Green
write-host "Creating output file $file"
write-host "Done!"
[system.Console]::ForegroundColor = [System.ConsoleColor]::Gray

No comments:

Post a Comment