-
Notifications
You must be signed in to change notification settings - Fork 106
/
GetUsersInEmergencyLocation.ps1
148 lines (138 loc) · 5.25 KB
/
GetUsersInEmergencyLocation.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<#
.NOTES
===========================================================================
Created on: 11/23/2020 9:16 PM
Created by: Vikas Sukhija
Organization: TechWizard.cloud
Filename: GetUsersInEmergencyLocation.ps1
===========================================================================
.DESCRIPTION
Extract Teams users in emegency Location
https://techwizard.cloud/2020/11/25/teams-exporting-users-in-emergency-location/
#>
###########################################################################
param (
[string]$locationid = $(Read-Host "Enter the locationsID"),
[string]$CivicAddressId = $(Read-Host "Enter the Civic AdressID"),
[string]$domain = $(Read-Host "Enter the onmicrosoft domain")
)
function LaunchSOL
{
param
(
[Parameter(Mandatory = $true)]
$Domain,
[Parameter(Mandatory = $false)]
$Credential
)
Write-Host -Object "Enter Skype Online Credentials" -ForegroundColor Green
$dommicrosoft = $domain + ".onmicrosoft.com"
$CSSession = New-CsOnlineSession -Credential $Credential -OverrideAdminDomain $dommicrosoft
Import-Module (Import-PSSession -Session $CSSession -AllowClobber) -Prefix SOL -Global
} #Function LaunchSOL
Function RemoveSOL
{
$Session = Get-PSSession | Where-Object -FilterScript { $_.ComputerName -like "*.online.lync.com" }
Remove-PSSession $Session
} #Function RemoveSOL
function New-FolderCreation
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$foldername
)
$logpath = (Get-Location).path + "\" + "$foldername"
$testlogpath = Test-Path -Path $logpath
if($testlogpath -eq $false)
{
#Start-ProgressBar -Title "Creating $foldername folder" -Timer 10
$null = New-Item -Path (Get-Location).path -Name $foldername -Type directory
}
}
function Write-Log
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,ParameterSetName = 'Create')]
[array]$Name,
[Parameter(Mandatory = $true,ParameterSetName = 'Create')]
[string]$Ext,
[Parameter(Mandatory = $true,ParameterSetName = 'Create')]
[string]$folder,
[Parameter(ParameterSetName = 'Create',Position = 0)][switch]$Create,
[Parameter(Mandatory = $true,ParameterSetName = 'Message')]
[String]$message,
[Parameter(Mandatory = $true,ParameterSetName = 'Message')]
[String]$path,
[Parameter(Mandatory = $false,ParameterSetName = 'Message')]
[ValidateSet('Information','Warning','Error')]
[string]$Severity = 'Information',
[Parameter(ParameterSetName = 'Message',Position = 0)][Switch]$MSG
)
switch ($PsCmdlet.ParameterSetName) {
"Create"
{
$log = @()
$date1 = Get-Date -Format d
$date1 = $date1.ToString().Replace("/", "-")
$time = Get-Date -Format t
$time = $time.ToString().Replace(":", "-")
$time = $time.ToString().Replace(" ", "")
New-FolderCreation -foldername $folder
foreach ($n in $Name)
{$log += (Get-Location).Path + "\" + $folder + "\" + $n + "_" + $date1 + "_" + $time + "_.$Ext"}
return $log
}
"Message"
{
$date = Get-Date
$concatmessage = "|$date" + "| |" + $message +"| |" + "$Severity|"
switch($Severity){
"Information"{Write-Host -Object $concatmessage -ForegroundColor Green}
"Warning"{Write-Host -Object $concatmessage -ForegroundColor Yellow}
"Error"{Write-Host -Object $concatmessage -ForegroundColor Red}
}
Add-Content -Path $path -Value $concatmessage
}
}
} #Function Write-Log
#################Logs and reports###########################
$log = Write-Log -Name "GetUsersInEmergencyLocation-Log" -folder "logs" -Ext "log"
$Report = Write-Log -Name "GetUsersInEmergencyLocation-Report" -folder "Report" -Ext "csv"
################connect to SOl###############################
try
{
LaunchSOL -Domain $domain
Write-log -message "loaded.... SKOB Online Module" -path $log
}
catch
{
$exception = $_.Exception
Write-Log -Message "Error loading Module" -path $log -Severity Error
Write-Log -Message $exception -path $log -Severity error
exit;
}
##################################################################
Write-log -message "loaded all users with locationID: $locationid and CivicAddressID:$CivicAddressId" -path $log
$users = Get-SOLCsOnlineVoiceUser -LocationId $locationid -CivicAddressId $CivicAddressId
Write-log -message "loaded users $($users.count)" -path $log
$collection =@()
foreach($u in $users){
$mcoll = "" | Select-Object Name, userprincipalName, locationid, CivicAddressId, Number
$csuser = get-solcsonlineuser -identity $u.id | Select-Object userprincipalname
$mcoll.Name = $u.name
$mcoll.userprincipalName = $csuser.userprincipalname
$mcoll.locationid = $locationid
$mcoll.CivicAddressId = $CivicAddressId
$mcoll.Number = $u.Number
$collection+=$mcoll
Write-log -message "exporting..........$($csuser.userprincipalname)" -path $log
}
Write-log -message "export to CSV file" -path $log
$collection | Export-Csv $report -NoTypeInformation
Write-log -message "Removing SKOB Online Shell" -path $log
RemoveSOL
#################################################################