2

I am trying to remove a value of a user profile date field. We have a date field, SPS-HireDate, that I would like to clear in certain circumstances.

I am using PowerShell, specifically Set-PnPUserProfileProperty.

The Set-PnPUserProfileProperty is really just calling PeopleManager.SetSingleValueProfileProperty(AccountName, PropertyName, Value); behind the scenes.

Set-PnPUserProfileProperty -Account $UserUPN -Property 'SPS-HireDate' -Value $EmptyDate

I have tried

$EmptyDate = ""
$EmptyDate = $null
$EmptyDate = [DateTime]::MinValue
[Nullable[DateTime]]$EmptyDate = $null

How can I remove the value from a User Profile Property Date field using C# or PowerShell CSOM?

2

Using the following PowerShell:

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

$SiteURL="https://xxx-admin.sharepoint.com"
$UserName="dennis@xxx.onmicrosoft.com"
$Password = "xxx"
$AccountName="dennis@xxx.onmicrosoft.com"
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$SecurePassword)

#Bind to Site Collection
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$ctx.Credentials = $Creds

$PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($ctx)
$PeopleManager.SetSingleValueProfileProperty("i:0#.f|membership|"+$AccountName,"SPS-HireDate", "")
$ctx.ExecuteQuery()
  • Interesting. I'll try SetSingleValueProfileProperty by itself and see if it works. I won't be able to get to it until tomorrow though. – James Grizzle Oct 18 '17 at 13:35
  • Any update? Did you solve this issue? – LZ_MSFT Nov 9 '17 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.