##################################### # # Staff O365 Full Import For IDB # ##################################### # # Global Settings $tenant = "usceduau.onmicrosoft.com" $admin = "svc_fim0365-staff@" + $tenant #prod$password="01000000d08c9ddf0115d1118c7a00c04fc297eb0100000008f50f5d133c224685faf482b957eba40000000002000000000003660000c0000000100000005cbd9edcc780fd36f1e05a85b279e4d80000000004800000a000000010000000e95bc913cf445c2036525a63fded551918000000323cf2420bc7e736e42d67d76380d7ae991c620436f207e314000000d78c7ea7c133788f67ef39e56a348f7c714b142d" $password="01000000d08c9ddf0115d1118c7a00c04fc297eb010000003b203419e86dfd48b9160d615d5dc1780000000002000000000003660000c000000010000000b427eb6a065e3f5f9d07687b2f89fcb20000000004800000a000000010000000a7d46f6775e9d15ddf7dca1e8366c67c18000000f9fc2dc06a372d192b335e3f9691fac04dea1e55a4d8ae751400000035677e78843b0802f12404daea2cecdb2d82b76a" $mycreds = New-Object -TypeName System.Management.Automation.PSCredential $admin,($password | ConvertTo-SecureString) $threshold = 46001 # # ##################################### $sess=Connect-MsolService -Credential $mycreds $iter = 1 while ($iter -lt 5) { $O365Users = $null [Array]$O365Users = Get-MsolUser -All -ErrorVariable err -WarningVariable warn $usercount = $O365Users.length $logfile="C:\USC\O365counts.txt" $file="C:\USC\O365Staff.txt" get-date | Out-file $file get-date | Out-file $logfile -append "Number of users "| Out-file $file -append $usercount | Out-file $file -append "Number of users "| Out-file $logfile -append $usercount | Out-file $logfile -append if ($usercount -gt $threshold) { $iter = 6 } $iter++ sleep 20 } if ($usercount -lt $threshold) { Throw "The MSOL-GetUser command did not get everyone warning: $warn error: $err" } Foreach($msoluser in $O365Users) { #$UsrAlias = $msoluser.UserPrincipalName.replace("@"+(get-msoldomain).Name,"") $UsrAlias = $msoluser.UserPrincipalName.ToLower().replace("@usc.edu.au","") $lic = $msoluser.Licenses.AccountSku.SkuPartNumber -join ', ' $entity = $entities.Create(); $entity['ID'] = $UsrAlias; if($lic){ $entity['License'] = $lic; $disoptarr = ($msoluser.Licenses.ServiceStatus).Where({$_.ProvisioningStatus -eq "Disabled"}).ServicePlan.ServiceName; $entity['DisabledOptions'] = $disoptarr -join ', ' } $entity['isLicensed'] = $msoluser.isLicensed $entity.Commit(); $out="$UsrAlias,$lic,$entity['DisabledOptions'],$entity['isLicensed']" $out | Out-file $file -append }