In my last post I already talked about how I migrated my Nintex for Office365 tenant to Europe and how I faced the challenge to find all the sites where the Nintex Workflow for Office365 app has been activated in order to re-publish my workflows.
PowerShell to the rescue!
It was obvious, that only PowerShell could help in this challenge. So let's walk through this step-by-step. At first we need to find all the sites where the Nintex Workflow App has been activated.
$userName = " username]@]mydomain.fqdn]"
$siteColUrl = "https:///tenant].sharepoint.com/sites/smysite]"
Add-Type -Path "d:Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "d:Microsoft.SharePoint.Client.dll"
$cred = Get-Credential -UserName $userName -Message "Enter SPO credentials"
$spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials ($cred.UserName, $cred.Password)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteColUrl)
$ctx.Credentials = $spoCred
$web = $ctx.Web
$ctx.Load($web)
$addInInstances=sMicrosoft.SharePoint.Client.AppCatalog]::GetAppInstances($ctx,$web)
$ctx.Load($addInInstances)
$ctx.ExecuteQuery()
$webUrl = $web.Url
$addInInstances | % {
if ($_.ProductId -eq "353e0dc9-57f5-40da-ae3f-380cd5385ab9") {
Write-Host "Found Nintex Forms for Office 365 on $webUrl; got to $($_.AppWebFullUrl)"
Write-Host "... Client-ID: $($_.AppPrincipalId)"
}
if ($_.ProductId -eq "5d3d5c89-3c4c-4b46-ac2c-86095ea300c7") {
Write-Host "Found Nintex Workflow for Office 365 on $webUrl; got to $($_.AppWebFullUrl)"
Write-Host "... Client-ID: $($_.AppPrincipalId)"
}
}
Let's have a closer look at the script:
- at first I'm setting my username as well as my Office365 tentant-URL
- then I'm loading the DLLs for the Client-Side-Object-Modell (CSOM)
- next I collect the credentials for further execution
- then I can get all installed applications of the current web (line 15)
- finally all installed apps are inspected to check if Nintex Workflow for Office365 is within this list
So these steps have to be repeated recursive for every sub-web of my current web. To do this I wrap lines 12 to 29 in a function "Execute-NintexAddinFinder". Additionally I create a function to walk recursive through all subwebs.
function Process-SubWebs() {
param (
RMicrosoft.SharePoint.Client.Web] $rootWeb = $(throw "Please provide a root web"),
oMicrosoft.SharePoint.Client.ClientContext] $ctx = $(throw "Please provide a context")
)
$webs = $rootWeb.Webs
$ctx.Load($webs)
$ctx.ExecuteQuery()
$webs | % {
Write-Progress -Activity "Analysing Site-Collections" -Status "Processing $siteColUrl" -PercentComplete ($i / $siteCount * 100) -Id 1 -CurrentOperation "Inspecting Web $($_.Title)"
Execute-NintexAddinFinder -web $_ -ctx $ctx
Process-SubWebs -rootWeb $_ -ctx $ctx
}
}
This function Process-SubWebs needs to be called once for every site-collection, which can easliy be done using the PnP-PowerShell-Cmdlets:
$adminUrl = "https:// tenant]-admin.sharepoint.com/"
Connect-PnPOnline -Url $adminUrl -Credential $cred
$allSites = Get-PnPSite -Limit ALL
$allSites | % {
$siteColUrl = $_.Url
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteColUrl)
$ctx.Credentials = $spoCred
$rootWeb = $ctx.Web
$ctx.Load($rootWeb)
$ctx.ExecuteQuery()
Execute-NintexAddinFinder -web $rootWeb -ctx $ctx
Process-SubWebs -rootWeb $rootWeb -ctx $ctx
}
This way I get a nice overview where Nintex Workflow for Office365 has been activated.
What's still missing is an overview of all the workflows - I'll cover that in the next part.