Skip to content

Instantly share code, notes, and snippets.

@shurick81
Created June 14, 2019 16:28
Show Gist options
  • Save shurick81/1b1f74795a080e1be0c7bad614e3b4dd to your computer and use it in GitHub Desktop.
Save shurick81/1b1f74795a080e1be0c7bad614e3b4dd to your computer and use it in GitHub Desktop.
Add-PSSnapin Microsoft.SharePoint.PowerShell
New-SPTrustedSecurityTokenIssuer -Name "crm" -IsTrustBroker:$false -MetadataEndpoint "https://crm.contoso.local/Contoso/XrmServices/2015/metadataendpoint.svc/json?orgName=Contoso";
$CrmRealmId = Get-Content "c:\Install\CRM\OrganizationId.txt"
$Identifier = "00000007-0000-0000-c000-000000000000@" + $CrmRealmId
$site = Get-SPSite "https://crmdocuments.contoso.local"
Register-SPAppPrincipal -site $site.RootWeb -NameIdentifier $Identifier -DisplayName "crm"
$app = Get-SPAppPrincipal -NameIdentifier $Identifier -Site $site.Rootweb
Set-SPAppPrincipalPermission -AppPrincipal $app -Site $site.Rootweb -Scope "sitecollection" -Right "FullControl" -EnableAppOnlyPolicy
#New-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "EmailAddress" -SameAsIncoming
$url = "https://crmdocuments.contoso.local"
$securedPassword = ConvertTo-SecureString "c0mp1Expa~~" -AsPlainText -Force
$SPInstallAccountCredential = New-Object System.Management.Automation.PSCredential( "contoso\Svc_sp_inst", $securedPassword );
Connect-PnPOnline $url -Credential $SPInstallAccountCredential -NoTelemetry
Apply-PnPProvisioningTemplate C:\projects\SOS-sharepoint\src\spfarm\spdoccentertemplate.xml
$userName = "contoso\_crmadmin";
$securedPassword = ConvertTo-SecureString "blablabla" -AsPlainText -Force
$CRMInstallAccountCredential = New-Object System.Management.Automation.PSCredential( "contoso\_crmadmin", $securedPassword );
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
$attemptsLeft = $timesThreshold;
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext( $url );
$ctx.Credentials = $CRMInstallAccountCredential.GetNetworkCredential();
$peopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager( $ctx );
$userProfile = $peopleManager.GetPropertiesFor( $userName );
$ctx.Load( $userProfile )
$ctx.ExecuteQuery()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment