1.0.19/Public/get-AllegisSNOWNewHires.ps1
function get-AllegisSNOWNewHires{ Param( [string]$snowOrg, [pscredential]$snowcred, [string]$snowFilter='u_provision_to_sailpoint=true^u_new_hire_item_id.active=true', [pscredential]$sqlcred, [string]$sqlserver, [string]$sqltable ) $method = 'get' $uri = "https://$snowOrg.service-now.com/api/now/table/sys_user?sysparm_query=$snowfilter" $command="`$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((""{0}:{1}"" -f '$($snowcred.username)', '$($snowcred.getnetworkcredentials().password)'))) `$headers = New-Object ""System.Collections.Generic.Dictionary[[String],[String]]"" `$headers.Add('Authorization',('Basic {0}' -f `$base64AuthInfo)) `$headers.Add('Accept','application/json') `$response=Invoke-RestMethod -Headers `$headers -Method '$method' -Uri '$uri' -UseBasicParsing -FollowRelLink #-MaximumFollowRelLink 2 return `$response.result | convertto-json " $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) $results=& 'C:\Program Files\PowerShell\6-preview\pwsh.exe' -encodedcommand $encodedCommand $json=$results | ConvertFrom-Json return $json foreach ($user in $json) { if ($user.email.length + $user.u_nick_name.Length + $user.user_name.Length -eq 0 -and !!$user.first_name -and !!$user.last_name -and !!$user.u_ag_user_domain) { $i=0 do{ $username=get-AllegisUsername -scheme firstInitial -firstname $user.first_name -lastname $user.last_name -maxlength 14 -iteration $i $i++ }until(!(get-AllegisInUseUsername -username $username -corpAD $true -ASQL $true -sqlserver $sqlserver -sqlusername $sqlusername.username -sqltable $sqltable -snow $true -snowEnv $snowOrg -snowcred $snowCred)) $username=$username+'@'+(if (!!$user.u_ag_user_domain){'allegisgroup.com'}else{$user.u_ag_user_domain}) set-AllegisSnowUsername -snowEnv $snoworg -snowCred $snowCred -usersysid $user.sys_id -upn $username } } ###copy to new hire api } |