Skip to content

Commit

Permalink
Added ClientId in Util scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tarjeieo committed Sep 10, 2024
1 parent 6e0c30f commit 37adb53
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1,673 deletions.
Binary file not shown.
Binary file not shown.
1,660 changes: 0 additions & 1,660 deletions Install/PnP.PowerShell/PSGetModuleInfo.xml

This file was deleted.

6 changes: 4 additions & 2 deletions Install/Scripts/CleanupProsjektportalenInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ Param(
[Parameter(Mandatory = $true)]
[string]$Url,
[Parameter(Mandatory = $false)]
[switch]$Force
[switch]$Force,
[Parameter(Mandatory = $false, HelpMessage = "Client ID of the Entra Id application used for interactive logins. Defaults to the multi-tenant Prosjektportalen app")]
[string]$ClientId = "da6c31a6-b557-4ac3-9994-7315da06ea3a"
)

Write-Host "This script will clean up traces of a Prosjektportalen installation"
Expand Down Expand Up @@ -35,7 +37,7 @@ $AdminSiteUrl = (@($Uri.Scheme, "://", $Uri.Authority) -join "").Replace(".share

Set-PnPTraceLog -Off

Connect-PnPOnline -Url $AdminSiteUrl -Interactive
Connect-PnPOnline -Url $AdminSiteUrl -Interactive -ClientId $ClientId

Write-Host "🗃️ Retrieving all sites of the Project Portal hub..."
$ProjectsHub = Get-PnPTenantSite -Identity $Url -ErrorAction SilentlyContinue
Expand Down
12 changes: 7 additions & 5 deletions Install/Scripts/Ensure-AdminUsers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ param (
$GrantPermissions,
[Parameter( Mandatory = $false, Position = 2 )]
[switch]
$GrantPermissionsAndDelete
$GrantPermissionsAndDelete,
[Parameter(Mandatory = $false, HelpMessage = "Client ID of the Entra Id application used for interactive logins. Defaults to the multi-tenant Prosjektportalen app")]
[string]$ClientId = "da6c31a6-b557-4ac3-9994-7315da06ea3a"
)

$PortfolioAdminGroupName = "Porteføljeadministratorer"
Expand All @@ -17,7 +19,7 @@ $TenantAdminUrl = (@($PortfolioUri.Scheme, "://", $PortfolioUri.Authority) -join

function GetPortfolioadminUsers($HubUrl){
Write-Host "Looking for portfolio admin users in: $HubUrl (using TenantAdminUrl: $TenantAdminUrl)" -ForegroundColor DarkGreen
Connect-PnPOnline -Url $HubUrl -TenantAdminUrl $TenantAdminUrl -Interactive
Connect-PnPOnline -Url $HubUrl -TenantAdminUrl $TenantAdminUrl -Interactive -ClientId $ClientId

## Getting security group (Porteføljeadministratorer) and returning its members
$Group = Get-PnPSiteGroup -Group $PortfolioAdminGroupName
Expand All @@ -37,7 +39,7 @@ function GrantPermissions ($Url, $Members) {
$CurrentUser = Get-PnPProperty -Property CurrentUser -ClientObject (Get-PnPContext).Web
Write-Host "Granting owner permissions to site collection $Url for current user $($CurrentUser.Email)" -ForegroundColor DarkGreen
Set-PnPTenantSite -Url $Url -Owners $CurrentUser.Email
Connect-PnPOnline -Url $Url -TenantAdminUrl $TenantAdminUrl -Interactive
Connect-PnPOnline -Url $Url -TenantAdminUrl $TenantAdminUrl -Interactive -clientId $ClientId

## Adding security group (if not created)
$Group = Get-PnPSiteGroup -Site $Url -Group $PortfolioAdminGroupName -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -72,7 +74,7 @@ if (-not (Get-Module | Where-Object { $_.Name -like "PnP.PowerShell" }) ) {
Import-Module PnP.PowerShell
}

Connect-PnPOnline -TenantAdminUrl $TenantAdminUrl -Url $PortfolioUrl -Interactive
Connect-PnPOnline -TenantAdminUrl $TenantAdminUrl -Url $PortfolioUrl -Interactive -ClientId $ClientId
try{
$Children = Get-PnPHubSiteChild
}catch{
Expand All @@ -93,7 +95,7 @@ if ($GrantPermissions) {
} elseif($GrantPermissionsAndDelete) {
$Children | ForEach-Object {
$ChildSiteUrl = $_
Connect-PnPOnline -Url $ChildSiteUrl -TenantAdminUrl $TenantAdminUrl -Interactive;
Connect-PnPOnline -Url $ChildSiteUrl -TenantAdminUrl $TenantAdminUrl -Interactive -ClientId $ClientId
$Group = Get-PnPSiteGroup -Group $PortfolioAdminGroupName
if($Group -and $Group.Count -gt 0){
$Members = Get-PnPGroupMember -Group $PortfolioAdminGroupName
Expand Down
10 changes: 6 additions & 4 deletions Install/Scripts/Ensure-PlannerPlans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ param (
$CurrentUser,
[Parameter( Mandatory = $false, Position = 3 )]
[switch]
$GrantPermissions
$GrantPermissions,
[Parameter(Mandatory = $false, HelpMessage = "Client ID of the Entra Id application used for interactive logins. Defaults to the multi-tenant Prosjektportalen app")]
[string]$ClientId = "da6c31a6-b557-4ac3-9994-7315da06ea3a"
)

$GroupsWhereAdded = [System.Collections.ArrayList]@()

function GrantPermissions ($Url) {
Write-Host "`tGranting owner permissions to site collection $Url"
Set-PnPTenantSite -Url $Url -Owners $CurrentUser
Connect-PnPOnline -Url $Url -TenantAdminUrl $TenantAdminUrl -Interactive
Connect-PnPOnline -Url $Url -TenantAdminUrl $TenantAdminUrl -Interactive -ClientId $ClientId
$GroupId = (Get-PnPSite -Includes GroupId -ErrorAction Ignore).GroupId.toString()
Write-Host "`tGranting owner permissions to group $GroupId"
Add-PnPMicrosoft365GroupOwner -Identity -Users $CurrentUser
Expand All @@ -44,7 +46,7 @@ if (-not (Get-Module | Where-Object { $_.Name -like "PnP.PowerShell" }) ) {
Import-Module PnP.PowerShell
}

Connect-PnPOnline -TenantAdminUrl $TenantAdminUrl -Url $PortfolioUrl -Interactive
Connect-PnPOnline -TenantAdminUrl $TenantAdminUrl -Url $PortfolioUrl -Interactive -clientId $ClientId

$Children = Get-PnPHubSiteChild

Expand All @@ -58,7 +60,7 @@ else {
$Children | ForEach-Object {
$ChildSiteUrl = $_

Connect-PnPOnline -Url $ChildSiteUrl -TenantAdminUrl $TenantAdminUrl -Interactive;
Connect-PnPOnline -Url $ChildSiteUrl -TenantAdminUrl $TenantAdminUrl -Interactive -clientId $ClientId
$GroupId = (Get-PnPSite -Includes GroupId -ErrorAction Ignore).GroupId.toString()
$PlannerPlan = Get-PnPPlannerPlan -Group $GroupId

Expand Down
6 changes: 4 additions & 2 deletions Install/Scripts/UpgradeAllSitesToLatest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ Param(
[Parameter(Mandatory = $true)]
[string]$Url,
[Parameter(Mandatory = $false, HelpMessage = "Used by Continuous Integration")]
[string]$CI
[string]$CI,
[Parameter(Mandatory = $false, HelpMessage = "Client ID of the Entra Id application used for interactive logins. Defaults to the multi-tenant Prosjektportalen app")]
[string]$ClientId = "da6c31a6-b557-4ac3-9994-7315da06ea3a"
)


Expand Down Expand Up @@ -45,7 +47,7 @@ function Connect-SharePoint {
if ($null -ne $global:__PnPConnection.ClientId) {
Connect-PnPOnline -Url $Url -Interactive -ClientId $global:__PnPConnection.ClientId -ErrorAction Stop -WarningAction Ignore
}
Connect-PnPOnline -Url $Url -Interactive -ErrorAction Stop -WarningAction Ignore
Connect-PnPOnline -Url $Url -Interactive -ClientId $ClientId -ErrorAction Stop -WarningAction Ignore
$global:__PnPConnection = Get-PnPConnection
}
}
Expand Down

0 comments on commit 37adb53

Please sign in to comment.