Last active
December 2, 2022 05:36
-
-
Save paulczy/05fc11d79a563e2fe87c536763eca14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$serverUrl = Read-Host -Prompt "Dynamics URL (ex: https://akoyago.crm.dynamics.com)" | |
$connectionString = "AuthType=OAuth;Integrated Security=true;Url=$serverUrl;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;TokenCacheStorePath=c:\MyTokenCache\msal_cache.data;LoginPrompt=Auto" | |
# Login to PowerApps for the Admin commands | |
Write-Host "Installing Module: Microsoft.PowerApps.Administration.PowerShell" | |
Install-Module Microsoft.PowerApps.Administration.PowerShell -Force -Scope CurrentUser | |
#Write-Host "Login to PowerApps for the Admin commands" | |
# Add-PowerAppsAccount | |
# Login to PowerApps for the Xrm.Data commands | |
Write-Host "Installing Module: Microsoft.Xrm.Data.PowerShell -Force -Scope CurrentUser" | |
Install-Module Microsoft.Xrm.Data.PowerShell -Force -Scope CurrentUser | |
Write-Host "Login to PowerApps for the Xrm.Data commands" | |
$conn = Get-CrmConnection -ConnectionString $connectionString | |
# Get the Orgid | |
$org = (Get-CrmRecords -conn $conn -EntityLogicalName organization).CrmRecords[0] | |
$orgid =$org.organizationid | |
# Get connection references in the solution that are connected | |
Write-Host "Get Connected Connection References" | |
$connectionrefFetch = @" | |
<fetch> | |
<entity name='connectionreference' > | |
<attribute name="connectionreferenceid" /> | |
<attribute name="connectionid" /> | |
<filter><condition attribute='connectionid' operator='not-null' /></filter> | |
<link-entity name='solutioncomponent' from='objectid' to='connectionreferenceid' > | |
<link-entity name='solution' from='solutionid' to='solutionid' > | |
<filter> | |
<condition attribute='uniquename' operator='eq' value='Akoyanet' /> | |
</filter> | |
</link-entity> | |
</link-entity> | |
</entity> | |
</fetch> | |
"@; | |
$connectionsrefs = (Get-CrmRecordsByFetch -conn $conn -Fetch $connectionrefFetch -Verbose).CrmRecords | |
# If there are no connection refeferences that are connected then exit | |
if ($connectionsrefs.Count -eq 0) | |
{ | |
Write-Error "No Connection References that are connected in the solution '$(BuildToolsSolutionName)'" | |
return 0 | |
} | |
$existingconnectionreferences = (ConvertTo-Json ($connectionsrefs | Select-Object -Property connectionreferenceid, connectionid)) -replace "`n|`r","" | |
Write-Host "Connection References:$existingconnectionreferences" | |
# Get the first connection reference connector that is not null and load it to find who it was created by | |
$connections = Get-AdminPowerAppConnection -EnvironmentName $conn.EnvironmentId -Filter $connectionsrefs[0].connectionid | |
# If the first connection reference doesn't link to a connection, then exit | |
if ($connections.Count -eq 0) | |
{ | |
Write-Error "Unable to find Connection linked to ConnectionReference, quitting." | |
return 0 | |
} | |
$user = Get-CrmRecords -conn $conn -EntityLogicalName systemuser -FilterAttribute azureactivedirectoryobjectid -FilterOperator eq -FilterValue $connections[0].CreatedBy.id | |
# Create a new Connection to impersonate the creator of the connection reference | |
$impersonatedconn = Get-CrmConnection -ConnectionString $connectionString | |
$impersonatedconn.OrganizationWebProxyClient.CallerId = $user.CrmRecords[0].systemuserid | |
Write-Host "GOapply Add All Applications to Review Group"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '2c618902-7de2-ec11-bb3d-0022480c598c' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Add Request to Review Group"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '5b3644c7-00f7-ec11-bb3d-000d3a5c0906' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Add to Review Group"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id 'ef6d98cd-c1c4-ec11-a7b6-000d3a3be81d' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Advance to Final Report Phase"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '01472d0b-f217-ed11-b83e-002248081438' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply AutoFill Next Phase"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id 'c566a946-22a6-ec11-983f-0022480b67c1' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Document Move Version 2.0"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '93e74ef0-3976-ec11-8d21-000d3a5cf59d' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Duplicate Application"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '4e3cd5d3-c58a-ec11-93b0-000d3a5b26c0' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Duplicate Review Group"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id 'e98d7973-d2e1-ec11-bb3d-0022480c5141' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Duplicate Review Group and Reviewers"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '4a5431f9-d5e1-ec11-bb3d-0022480c598c' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Invite Constituent"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '76ae7a00-4e75-ec11-8943-00224809eefd' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOapply Invite Contact"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '33ccdc60-dd77-ec11-8d21-000d3a5cfdba' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOfund Invitation Email"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id 'eba79434-563b-ed11-9db1-000d3a59640f' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host "GOfund Move Documents Flow"; | |
Set-CrmRecordState -conn $impersonatedconn -EntityLogicalName workflow -Id '21197efa-da39-ed11-9db1-000d3a5a6918' -StateCode Activated -StatusCode Activated -Verbose -Debug; | |
Write-Host "Completed."; | |
Write-Host ""; | |
Write-Host "DONE."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment