forked from microsoft/MTC_FLWTeamsScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BulkAddFunctions.psm1
142 lines (123 loc) · 4.05 KB
/
BulkAddFunctions.psm1
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
<#
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant You
a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of
the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which
the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded;
and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’
fees, that arise or result from the use or distribution of the Sample Code.
Please note: None of the conditions outlined in the disclaimer above will supercede the terms and conditions contained within
the Premier Customer Services Description.
#>
<#
This module contains commonly used helper Functions
#>
# Helper function to read CSV files
Function Read-CSV {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[String]
$fileName
)
If (-not($array = Get-Content $fileName -ErrorAction SilentlyContinue | ConvertFrom-Csv)) {
Write-Host "ERROR FILE NOT FOUND: $fileName"
return $null
}
return $array
}
# Helper function to return the credentials for a service endpoint
Function Get-Creds {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[String]
$FileName
)
$global:az_keypath = "$ENV:LOCALAPPDATA\keys"
$appreg_cred = Import-Clixml -Path $global:az_keyPath\$FileName
return $appreg_cred
}
# Helper function to set the credentials for a service endpoint
Function Set-Creds {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[String]
$FileName
)
$global:az_keypath = "$ENV:LOCALAPPDATA\keys"
if (!(Test-Path $global:az_keypath)) {
mkdir $global:az_keypath
}
$appreg_cred = Get-Credential
$appreg_cred | Export-Clixml -Path $global:az_keyPath\$FileName -Confirm
return $appreg_cred
}
# Helper function to output exceptions in processing, i.e. where something already exists
Function Set-Exception {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[String]
$FileName,
[Parameter(Mandatory)]
[String]
$Module,
[Parameter(Mandatory)]
[String]
$Message
)
$EvtProperties = @{
Module = $Module
Message = $Message
}
$PSObj = New-Object -TypeName psobject -Property $EvtProperties
$PSObj | export-csv $fileName -Append
}
# Helper function to determine number of batches required for large scale, batch operations
Function Set-BatchIterations {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[Int32]
$userCount,
[Parameter(Mandatory)]
[Int32]
$batchSize
)
if ($userCount -gt $batchSize) {
$batchIterations = [math]::Round($userCount / $batchSize)
if (($userCount % $batchSize) -gt 0) {
$batchIterations += 1
}
}
else {
$batchIterations = 1
}
return $batchIterations
}
# Helper function to determine the upper limit of the next processing batch required for large scale, batch operations
Function Set-NextBatch {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[Int32]
$BatchStart,
[Parameter(Mandatory)]
[Int32]
$MaxBatchSize,
[Parameter(Mandatory)]
[Int32]
$UserCount
)
$UpperLimit = $BatchStart
if (($UpperLimit + $MaxBatchSize) -le $UserCount) {
$UpperLimit += $MaxBatchSize
}
else {
$UpperLimit = $UserCount
}
return $UpperLimit
}