|
| 1 | +function Get-SPOUserProperty |
| 2 | +{ |
| 3 | +param ( |
| 4 | + [Parameter(Mandatory=$true,Position=1)] |
| 5 | +[string]$Username, |
| 6 | + [Parameter(Mandatory=$true,Position=2)] |
| 7 | +$password, |
| 8 | + [Parameter(Mandatory=$true,Position=3)] |
| 9 | +[string] $url, |
| 10 | + [Parameter(Mandatory=$true,Position=4)] |
| 11 | +[string] $userLogin |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) |
| 17 | + $RestUrl=$url+"/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|"+$userLogin+"'" |
| 18 | + |
| 19 | + $request = [System.Net.WebRequest]::Create($RESTUrl) |
| 20 | + $request.Credentials = $Credentials |
| 21 | + $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") |
| 22 | + $request.Accept = "application/json;odata=verbose" |
| 23 | + [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get |
| 24 | + $request.Method=$Method |
| 25 | + $response = $request.GetResponse() |
| 26 | + $requestStream = $response.GetResponseStream() |
| 27 | + $read = New-Object System.IO.StreamReader $requestStream |
| 28 | + $data=$read.ReadToEnd() |
| 29 | + $results = $data | ConvertFrom-Json |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + return ($results.d.userprofileproperties.results) |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +#Paths to SDK |
| 53 | +Add-Type -Path "H:\Libraries\Microsoft.SharePoint.Client.dll" |
| 54 | +Add-Type -Path "H:\Libraries\Microsoft.SharePoint.Client.Runtime.dll" |
| 55 | + |
| 56 | + |
| 57 | +#Enter the data |
| 58 | + |
| 59 | +$SiteUrl="https://t321.sharepoint.com" |
| 60 | +$AdminCenter="https://t321-admin.sharepoint.com" |
| 61 | +$ExportTo="C:\Users\Arletka\Documents\SpUsers3.csv" |
| 62 | + |
| 63 | +Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking |
| 64 | +$cred=Get-Credential |
| 65 | +Connect-SPOService $AdminCenter -Credential $cred |
| 66 | +$users=Get-SPOUser -Site $SiteUrl |
| 67 | + |
| 68 | + |
| 69 | +foreach($user in $users) |
| 70 | +{ |
| 71 | + Write-Verbose $user.LoginName |
| 72 | + $props=Get-SPOUserProperty -Username $cred.UserName -Url $SiteUrl -password $cred.Password -userLogin $user.LoginName |
| 73 | + $uss=New-Object PSObject |
| 74 | + foreach($prop in $props) |
| 75 | + { |
| 76 | + $uss | Add-Member -MemberType NoteProperty -Name $prop.Key -Value $prop.Value |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + $uss | Export-Csv -Path $ExportTo -Append -Force |
| 81 | +} |
| 82 | + |
0 commit comments