Public/start-AllegisFIMTGSUsersPreAD.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
function start-AllegisFIMTGSUsersPreAD{
param(
    [boolean]$corpad=$true,
    [boolean]$asql=$false,
    [boolean]$snow=$false,
    [string]$snowOrg,
    [pscredential]$snowCred,
    [string]$sqlserver,
    [string]$sqltable,
    [pscredential]$sqlusername,
    [boolean]$interactive=$false,
    [string]$fimhost,
    [string]$fimpowershellmodule,
    [PSCredential]$fimcred,
    [PSCredential]$adcred,
    [string]$adforest
)
    $users=get-AllegisFIMfilter -filter "/Person[(PSTimeAndExpense = True) and (TGS_ExtUser = True) and (not(Domain = 'CORPORATE'))]" -fimservice $fimhost -fimcred $fimcred
    "found $($users.count) TGS users in FIM"
    import-module $fimpowershellmodule
    $psusers=$users | Convert-FimExportToPSObject
    foreach ($person in $psusers){
        if (!!$person.FirstName -and !!$person.LastName -and !$person.accountname -and !!$person.initialPassword)
        {
            $i=0
            do{
            $username=get-AllegisUsername -scheme firstInitial -firstname $person.FirstName -lastname $person.LastName -maxlength 14 -iteration $i
            "checking $username availability for $($person.firstname) $($person.lastname)"
            $i++
            }until(!(get-AllegisInUseUsername -username $username -corpAD $corpad -ASQL $asql -sqlserver $sqlserver -sqlusername $sqlusername.username -sqltable $sqltable -snow $snow -snowEnv $snowOrg -snowcred $snowCred -fim $true -fimservice $fimhost -fimcred $fimcred -azureAD $false -adforest $adforest -adcred $adcred))
            if ($interactive){$answer=Read-Host "set $username to $($person.firstname) $($person.LastName)?"}else{$answer='y'}
            if ($answer='y'){
                "setting $username to $($person.firstname) $($person.LastName)"
                set-AllegisFIMTGSUser -objectid $person.ObjectID.Replace('urn:uuid:','') -accountname $username -fimcred $fimcred -fimservice $fimhost
            }
        }
    }
}