Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function Get-SPOUserProperty
{
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Username,
[Parameter(Mandatory=$true,Position=2)]
$password,
[Parameter(Mandatory=$true,Position=3)]
[string] $url,
[Parameter(Mandatory=$true,Position=4)]
[string] $userLogin
)



$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$RestUrl=$url+"/_api/sp.userprofiles.peoplemanager/getuserprofilepropertyfor(accountname=@v, propertyname='WorkEmail')?@v='i%3A0%23.f%7Cmembership%7C"+$userLogin+"'"

$request = [System.Net.WebRequest]::Create($RESTUrl)
$request.Credentials = $Credentials
$request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
$request.Accept = "application/json;odata=verbose"
[Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get
$request.Method=$Method
$response = $request.GetResponse()
$requestStream = $response.GetResponseStream()
$read = New-Object System.IO.StreamReader $requestStream
$data=$read.ReadToEnd()
# Because the string contains duplicate 'ID' keys.
$results = $data | ConvertFrom-Json



return ($results.d)








}









#Paths to SDK
Add-Type -Path "H:\Libraries\Microsoft.SharePoint.Client.dll"
Add-Type -Path "H:\Libraries\Microsoft.SharePoint.Client.Runtime.dll"


#Enter the data
$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
$username="t@t321.onmicrosoft.com"
$Url="https://t321.sharepoint.com/polski"
$userLogin="t@t321.onmicrosoft.com"




Get-SPOUserProperty -Username $username -Url $Url -password $AdminPassword -userLogin $userLogin
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
The script retrieves a WorkEmail property for a single SharePoint Online user.



The script uses the following endpoint to retrieve a user property:

/getuserprofilepropertyfor(accountname=@v, propertyname='<property name>')?@v='<account name>'



For more details, please consult:

User profiles REST API reference





### How to use?


Download, open the script and enter correct values in the following lines:

```PowerShell
#Enter the data
$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
$username="t@t321.onmicrosoft.com"
$Url="https://t321.sharepoint.com/polski"
$userLogin="t@t321.onmicrosoft.com"
```
Expected result