-
Notifications
You must be signed in to change notification settings - Fork 31
/
DisabledUsers.ps1
44 lines (38 loc) · 1.63 KB
/
DisabledUsers.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
#Get all disabled users
Add-PSSnapIn ShareFile
Function FindDisabledUsers{
Param ( [string]$UserType="employee")
$client = Get-SfClient -Name "c:\tmp\sfclient.sfps"
$entity = "";
switch ($UserType.ToLower()){
"employee"{
$entity = 'Accounts/Employees';
}
"client" {
$entity = 'Accounts/Clients';
}
}
#Pull all of the Account Employees or Clients
$sfUsers = Send-SfRequest -Client $client -Entity $entity
$fileOutput = @()
#Loop through each of the Employees or Clients returned from inital call
foreach($sfUserId in $sfUsers){
#Get full user information including security
$sfUser = Send-SfRequest -Client $client -Entity Users -Id $sfUserId.Id -Expand Security
#Output to Console Emails of disabled users
Write-Host $sfUser.Email
#check to see if security parameter IsDisabled is true
switch ($sfUser.Security.IsDisabled ) {
"True" {
$fileOutput += New-Object PSObject -Property @{'UserId'=$sfUserId.Id;'FullName'=$sfUser.FullName;'Email'=$sfUser.Email}
}
}
}
#Output CSV file with all disabled user information
$fileOutput | Export-Csv ("C:\tmp\" + $UserType + ".csv") -Force -NoTypeInformation
}
#Comment out this line after the first run in order to use the saved authentication file
New-SfClient -Name "c:\tmp\sfclient.sfps"
#Get-SfClient -Name "c:\tmp\sfclient.sfps"
FindDisabledUsers -UserType "employee";
FindDisabledUsers -UserType "client";