1- function Get-Workflows {
2- param (
3- [Parameter (Mandatory = $true , Position = 1 )]
4- [string ]$Username ,
5- [Parameter (Mandatory = $true , Position = 2 )]
6- $AdminPassword ,
7- [Parameter (Mandatory = $true , Position = 3 )]
8- [string ]$Url ,
9- [Parameter (Mandatory = $true , Position = 3 )]
10- [string ]$CSVPath
11- )
12- # $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
13- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url )
14- $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username , $AdminPassword )
15- $ctx.ExecuteQuery ()
1+ function Get-Workflows {
2+ param (
3+ [Parameter (Mandatory = $true , Position = 1 )]
4+ [string ]$Username ,
5+ [Parameter (Mandatory = $true , Position = 2 )]
6+ $AdminPassword ,
7+ [Parameter (Mandatory = $true , Position = 3 )]
8+ [string ]$Url ,
9+ [Parameter (Mandatory = $true , Position = 3 )]
10+ [string ]$CSVPath
11+ )
12+ # $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
13+ $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url )
14+ $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username , $AdminPassword )
15+ $ctx.ExecuteQuery ()
1616
17- $Lists = $ctx.Web.Lists
18- $ctx.Load ($ctx.Web )
19- $ctx.Load ($ctx.Web.Webs )
20- $ctx.Load ($Lists )
21- $ctx.ExecuteQuery ()
17+ $Lists = $ctx.Web.Lists
18+ $ctx.Load ($ctx.Web )
19+ $ctx.Load ($ctx.Web.Webs )
20+ $ctx.Load ($Lists )
21+ $ctx.ExecuteQuery ()
2222
23- foreach ( $ll in $Lists ){
24- $workflo = $ll.WorkflowAssociations ;
25- $ctx.Load ($workflo );
23+ foreach ( $ll in $Lists ) {
24+ $workflo = $ll.WorkflowAssociations ;
25+ $ctx.Load ($workflo );
2626
27- try {
28- $ctx.ExecuteQuery ();
29- Write-host $ll.Title $workflo.Count - ForegroundColor Green
30- }
31- catch [Net.WebException ] {
32- Write-Host " Failed for " $ll.Title - ForegroundColor Red
33- }
27+ try {
28+ $ctx.ExecuteQuery ();
29+ Write-host $ll.Title $workflo.Count - ForegroundColor Green
30+ }
31+ catch [Net.WebException ] {
32+ Write-Host " Failed for " $ll.Title - ForegroundColor Red
33+ }
3434
35- foreach ($workfloek in $workflo ){
36- $workfloek | Add-Member NoteProperty " SiteUrl" ($ctx.Web.Url )
37- $workfloek | Add-Member NoteProperty " ListTitle" ($ll.Title )
38- Write-Output $workfloek
35+ foreach ($workfloek in $workflo ) {
36+ $workfloek | Add-Member NoteProperty " SiteUrl" ($ctx.Web.Url )
37+ $workfloek | Add-Member NoteProperty " ListTitle" ($ll.Title )
38+ Write-Output $workfloek
3939
40- $workfloek | export-csv $CSVPath - Append
41- }
42- }
40+ $workfloek | export-csv $CSVPath - Append
41+ }
42+ }
4343
44- if ($ctx.Web.Webs.Count -gt 0 ){
45- Write-Host " --" - ForegroundColor DarkGreen
44+ if ($ctx.Web.Webs.Count -gt 0 ) {
45+ Write-Host " --" - ForegroundColor DarkGreen
4646
47- for ($i = 0 ; $i -lt $ctx.Web.Webs.Count ;$i ++ ){
48- Get-Workflows - Username $Username - AdminPassword $AdminPassword - Url $ctx.Web.Webs [$i ].Url - CSVPath $CSVPath
49- }
50- }
47+ for ($i = 0 ; $i -lt $ctx.Web.Webs.Count ; $i ++ ) {
48+ Get-Workflows - Username $Username - AdminPassword $AdminPassword - Url $ctx.Web.Webs [$i ].Url - CSVPath $CSVPath
49+ }
50+ }
5151}
5252
5353
@@ -58,13 +58,13 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens
5858Add-Type - Path " c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
5959
6060# Insert the credentials and the name of the admin site
61- $Username = " user@tenant.onmicrosoft.com"
62- $AdminPassword = Read-Host - Prompt " Password" - AsSecureString
63- $AdminUrl = " https://tenant-admin.sharepoint.com"
64- $CSVPath = " C:\Users\ivo\Desktop\SomePath.csv"
61+ $Username = " user@tenant.onmicrosoft.com"
62+ $AdminPassword = Read-Host - Prompt " Password" - AsSecureString
63+ $AdminUrl = " https://tenant-admin.sharepoint.com"
64+ $CSVPath = " C:\Users\ivo\Desktop\SomePath.csv"
6565
6666Connect-SPOService - Url $AdminUrl
67- $sites = get-spoSite
68- foreach ($site in $sites ){
69- Get-Workflows - Username $Username - AdminPassword $AdminPassword - Url $site.Url - CSVPath $CSVPath
67+ $sites = get-spoSite
68+ foreach ($site in $sites ) {
69+ Get-Workflows - Username $Username - AdminPassword $AdminPassword - Url $site.Url - CSVPath $CSVPath
7070}
0 commit comments