Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance Script: Add-CippUser.ps1 #236

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions ExecMaintenanceScripts/Scripts/Add-CippUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#requires -Version 7.2

[CmdletBinding(DefaultParameterSetName = 'interactive')]
Param(
[Parameter(Mandatory = $true, ParameterSetName = 'noninteractive')]
[ValidateSet('readonly', 'editor', 'admin')]
$Role,
[Parameter(Mandatory = $true, ParameterSetName = 'noninteractive')]
$SelectedUsers,
[Parameter(ParameterSetName = 'noninteractive')]
[Parameter(ParameterSetName = 'interactive')]
$ExpirationHours = 1
)

$ResourceGroup = '##RESOURCEGROUP##'
$Subscription = '##SUBSCRIPTION##'

if (!(Get-Module -ListAvailable Microsoft.PowerShell.ConsoleGuiTools)) {
Install-Module Microsoft.PowerShell.ConsoleGuiTools -Force
}

$Context = Get-AzContext
if (!$Context) {
Write-Host "`n- Connecting to Azure"
$Context = Connect-AzAccount -Subscription $Subscription
}
Write-Host "Connected to $($Context.Account)"

$swa = Get-AzStaticWebApp -ResourceGroupName $ResourceGroup
$Domain = $swa.CustomDomain | Select-Object -First 1

Write-Host "CIPP SWA - $($swa.name)"

if (!$Role) {
$Role = @('readonly', 'editor', 'admin') | Out-ConsoleGridView -OutputMode Single -Title 'Select CIPP Role'
}

$CurrentUsers = Get-AzStaticWebAppUser -Name $swa.name -ResourceGroupName $ResourceGroup -AuthProvider all | Select-Object DisplayName, Role

$AllUsers = Get-AzADUser -Filter "UserType eq 'Member'" | Select-Object DisplayName, UserPrincipalName

$SelectedUsers = $AllUsers | Where-Object { $CurrentUsers.DisplayName -notcontains $_.UserPrincipalName } | Out-ConsoleGridView -Title "Select users for role '$Role'"
Write-Host "Selected users: $($SelectedUsers.UserPrincipalName -join ', ')"

Write-Host 'Generating invite links...'
$InviteList = foreach ($User in $SelectedUsers) {
$UserInvite = @{
InputObject = $swa
Domain = $Domain
Provider = 'aad'
UserDetail = $User.UserPrincipalName
Role = $Role
NumHoursToExpiration = $ExpirationHours
}
$Invite = New-AzStaticWebAppUserRoleInvitationLink @UserInvite

[PSCustomObject]@{
User = $User.UserPrincipalName
Role = $Role
Link = $Invite.InvitationUrl
Expires = $Invite.ExpiresOn
}
}
$InviteList
$InviteList | Export-Csv -Path '.\cipp-invites.csv' -Append
Write-Host 'Invitations exported to .\cipp-invites.csv'
26 changes: 13 additions & 13 deletions ListAppsRepository/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$Search = $Request.Query.Search
$Repository = $Request.Query.Repository
$Search = $Request.Body.Search
$Repository = $Request.Body.Repository
$Packages = @()
$Message = ''
$IsError = $false
Expand All @@ -27,12 +27,13 @@ try {
if (($RepoPackages | Measure-Object).Count -gt 0) {
$Packages = foreach ($RepoPackage in $RepoPackages) {
[PSCustomObject]@{
Name = $RepoPackage.title.'#text'
Author = $RepoPackage.author.Name
Title = $RepoPackage.properties.Title
Version = $RepoPackage.properties.Version
Description = $RepoPackage.summary.'#text'
Created = Get-Date -Date $RepoPackage.properties.Created.'#text' -Format 'MM/dd/yyyy HH:mm:ss'
packagename = $RepoPackage.title.'#text'
author = $RepoPackage.author.Name
applicationName = $RepoPackage.properties.Title
version = $RepoPackage.properties.Version
description = $RepoPackage.summary.'#text'
customRepo = $Repository
created = Get-Date -Date $RepoPackage.properties.Created.'#text' -Format 'MM/dd/yyyy HH:mm:ss'
}
}
}
Expand All @@ -52,11 +53,10 @@ catch {
}

$PackageSearch = @{
Search = $Search
Repository = $Repository
Results = @($Packages)
Message = $Message
IsError = $IsError
Search = $Search
Results = @($Packages)
Message = $Message
IsError = $IsError
}

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Expand Down