-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path12-Reactive.ps1
114 lines (95 loc) · 3.62 KB
/
12-Reactive.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
Using module .\OneRoster.psm1
Param(
[String]$WorkFolder = ".\gclass-OneRoster\"
)
Get-Module -Name OneRoster| Remove-Module; Import-Module .\OneRoster.psm1
Import-Module PSGSuite
Get-Module -Name PSGSHelp | Remove-Module
Import-Module $PSScriptRoot\PSGSHelp.psm1
$TLOG = ((".\Logs\" + (Get-Date -Format u) +"-Reactive.log").Replace(" ", "-")).Replace(":", "-")
Start-Transcript -path $TLOG
#$ErrorActionPreference = "Stop"
#$ErrorActionPreference = "Inquire"
Function Reactive_students()
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[String]$WorkFolder
)
If ((Show-PSGSuiteConfig | Select-Object -ExpandProperty ConfigName) -ne "STUDENTS")
{
Write-Host -Object "Switching to STUDENTS"
Switch-PSGSuiteConfig -ConfigName STUDENTS
}
Write-Host -Object "Making list of users that should be active"
$emails = Read-ORUsers -FolderPath $WorkFolder -LoadXML $true | Where-Object -Property enabledUser -EQ -Value $true | Where-Object -Property role -EQ -Value ([OR_RoleType]::student) | Select-Object -ExpandProperty email
Write-Host -Object "There should $($emails.Count) active users"
Write-Host -Object "Getting List of inactives Google accounts users"
$GSUsers = Get-GSUser -Filter "isSuspended=true" -Projection Basic | Where-Object PrimaryEmail -In $emails
If ($GSUsers.Count -eq 0)
{
Write-Host "No inactive users found that should be active"
Return
}
$r = $GSUsers | ForEach-Object -Begin {
Write-Host -Object "Found $($GSUsers.Count) inactives users that should be active"
} -Process {
Update-GSUser -User $_.PrimaryEmail -Suspended:$False -Confirm:$false -Verbose
} -End {
Write-Host -Object "Done reenabling users"
} -Verbose
If ($r.Count -eq 0)
{
Write-Warning -Message "Could not active any Google accounts"
}
Else
{
Write-Host -Object "Reenabled $($r.Count) Google accounts"
}
return $r
}
Function Disactive_students()
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[String]$WorkFolder
)
If ((Show-PSGSuiteConfig | Select-Object -ExpandProperty ConfigName) -ne "STUDENTS")
{
Write-Host -Object "Switching to STUDENTS"
Switch-PSGSuiteConfig -ConfigName STUDENTS
}
Write-Host -Object "Making list of users that should be disabled"
$emails = Read-ORUsers -FolderPath $WorkFolder -LoadXML $false | Where-Object -Property enabledUser -EQ -Value $false | Where-Object -Property role -EQ -Value ([OR_RoleType]::student) | Select-Object -ExpandProperty email
Write-Host -Object "There should $($emails.Count) disabled users"
Write-Host -Object "Getting List of actives Google accounts users"
$GSUsers = Get-GSUser -Filter "isSuspended=False" -Projection Basic
$GSUsers = $GSUsers | Where-Object PrimaryEmail -In $emails
If ($GSUsers.Count -eq 0)
{
Write-Host "No active users found that should disactive"
Return
}
$r = $GSUsers | ForEach-Object -Begin {
Write-Host -Object "Found $($GSUsers.Count) actives users that should be inactive"
} -Process {
Update-GSUser -User $_.PrimaryEmail -Suspended:$true -Confirm:$false -Verbose
} -End {
Write-Host -Object "Done disabling users"
} -Verbose
If ($r.Count -eq 0)
{
Write-Warning -Message "Could not disable any Google accounts"
}
Else
{
Write-Host -Object "Disabled $($r.Count) Google accounts"
}
return $r
}
$r = Reactive_students -WorkFolder $WorkFolder -Verbose
$r = Disactive_students -WorkFolder $WorkFolder -Verbose