Skip to content

Commit

Permalink
Merge pull request #8 from BNWEIN/Dev
Browse files Browse the repository at this point in the history
Added Functions and Upped Version

Get-CIPPExcludedLicenses
Get-CIPPExcludedTenants
Set-CIPPExcludeLicense
Set-CIPPExcludeTenant
Set-CIPPPasswordSettings
Set-CIPPMailboxForwarding
Set-CIPPMailboxQuota
Set-CIPPDeviceAction
Set-CIPPOneDriveShortCut
Get-CIPPGDAPRoles
  • Loading branch information
BNWEIN authored Jun 27, 2024
2 parents 51b9c5a + de803dc commit 9f94a58
Show file tree
Hide file tree
Showing 27 changed files with 1,036 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CIPPAPIModule/CIPPAPIModule.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'CIPPAPIModule.psm1'

# Version number of this module.
ModuleVersion = '1.1.1'
ModuleVersion = '1.1.2'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
50 changes: 50 additions & 0 deletions CIPPAPIModule/private/Helpers/ConvertTo-FormattedArray.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<#
.SYNOPSIS
Converts an input array into a formatted array with labels.
.DESCRIPTION
The ConvertTo-FormattedArray function takes an input array and a label prefix as parameters. It iterates through each item in the input array and creates a formatted array with labels. Each item in the formatted array is a hashtable with two properties: 'value' and 'label'. The 'value' property contains the original item from the input array, and the 'label' property contains the concatenation of the label prefix and the item.
.PARAMETER inputArray
The input array to be converted into a formatted array.
.PARAMETER labelPrefix
The prefix to be added to each item in the formatted array as a label.
.EXAMPLE
$inputArray = 1, 2, 3
$labelPrefix = "Item"
ConvertTo-FormattedArray -inputArray $inputArray -labelPrefix $labelPrefix
This example will convert the input array [1, 2, 3] into a formatted array with labels. The resulting formatted array will be:
[
@{
value = 1
label = "Item - 1"
},
@{
value = 2
label = "Item - 2"
},
@{
value = 3
label = "Item - 3"
}
]
#>

function ConvertTo-FormattedArray {
param (
[array]$inputArray,
[string]$labelPrefix
)
$formattedArray = @()
foreach ($item in $inputArray) {
$formattedArray += @{
value = $item
label = "$labelPrefix - $item"
}
}
return $formattedArray
}
31 changes: 31 additions & 0 deletions CIPPAPIModule/public/CIPP/Settings/Get-CIPPExcludedLicenses.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#
.SYNOPSIS
Retrieves the list of excluded licenses from CIPP.
.DESCRIPTION
The Get-CIPPExcludedLicenses function is used to retrieve the list of excluded licenses from CIPP. It sends a request to the API endpoint "/api/execexcludelicenses" with the parameter "List" set to "true" to get the excluded license list.
.PARAMETER None
This function does not accept any parameters.
.EXAMPLE
Get-CIPPExcludedLicenses
# Retrieves the list of excluded licenses from the CIPP API.
.NOTES
This function requires the Invoke-CIPPRestMethod function to be available in the current session.
#>

function Get-CIPPExcludedLicenses {
[CmdletBinding()]
Param()

Write-Verbose "Getting Excluded License List"

$endpoint = "/api/execexcludelicenses"
$params = @{
List = "true"
}

Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params
}
43 changes: 43 additions & 0 deletions CIPPAPIModule/public/CIPP/Settings/Get-CIPPExcludedTenants.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<#
.SYNOPSIS
Retrieves a list of excluded tenants.
.DESCRIPTION
The Get-CIPPExcludedTenants function retrieves a list of excluded tenants from CIPP. It can retrieve all tenants or only the ones that are currently excluded.
.PARAMETER ListAll
Specifies whether to retrieve all tenants or only the ones that are currently excluded. By default, it retrieves only the excluded tenants.
.EXAMPLE
Get-CIPPExcludedTenants
Retrieves the list of currently excluded tenants.
.EXAMPLE
Get-CIPPExcludedTenants -ListAll
Retrieves the list of all tenants, including the ones that are not currently excluded.
#>

function Get-CIPPExcludedTenants {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[switch]$ListAll
)

Write-Verbose "Getting Excluded Tenants List"

$endpoint = "/api/execexcludetenant"
if (!$listAll) {
$params = @{
List = "true"
}
} else {
$params = @{
ListAll = "true"
}
}

Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params

}
71 changes: 71 additions & 0 deletions CIPPAPIModule/public/CIPP/Settings/Set-CIPPExcludeLicense.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<#
.SYNOPSIS
Sets the exclusion status of a license in CIPP.
.DESCRIPTION
The Set-CIPPExcludeLicense function is used to set the exclusion status of a license in CIPP. It allows you to add or remove a license from the exclusion list.
.PARAMETER LicenseGUID
Specifies the GUID of the license to be excluded or included.
.PARAMETER SKUName
Specifies the SKU name of the license.
.PARAMETER RemoveExclusion
Indicates whether to remove the license from the exclusion list. This switch cannot be used together with the -AddExclusion switch.
.PARAMETER AddExclusion
Indicates whether to add the license to the exclusion list. This switch cannot be used together with the -RemoveExclusion switch.
.EXAMPLE
Set-CIPPExcludeLicense -LicenseGUID "12345678-1234-1234-1234-1234567890AB" -SKUName "ExampleSKU" -RemoveExclusion
Removes the license with the specified GUID from the exclusion list.
.EXAMPLE
Set-CIPPExcludeLicense -LicenseGUID "12345678-1234-1234-1234-1234567890AB" -SKUName "ExampleSKU" -AddExclusion
Adds the license with the specified GUID to the exclusion list.
#>
function Set-CIPPExcludeLicense {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[guid]$LicenseGUID,
[Parameter(Mandatory = $true)]
[string]$SKUName,
[Parameter()]
[switch]$RemoveExclusion,
[Parameter()]
[switch]$AddExclusion
)

# Ensure only one of the switches is used
if ($AddExclusion -and $RemoveExclusion) {
throw "You cannot use both -AddExclusion and -RemoveExclusion switches at the same time."
}

if (-not $AddExclusion -and -not $RemoveExclusion) {
throw "You must specify either -AddExclusion or -RemoveExclusion switch."
}

$endpoint = "/api/execexcludelicenses"

if ($RemoveExclusion) {
$params = @{
GUID = $LicenseGUID
RemoveExclusion = $true
}
Write-Verbose "Removing License $LicenseGUID from the exclusion list."
Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params
} else {
$params = @{
AddExclusion = $true
}
$body = @{
GUID = $LicenseGUID
SKUName = $SKUName
}
Write-Verbose "Adding License $LicenseGUID to the exclusion list."
Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params -Body $body -Method POST
}
}
67 changes: 67 additions & 0 deletions CIPPAPIModule/public/CIPP/Settings/Set-CIPPExcludeTenant.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<#
.SYNOPSIS
Sets the exclusion status for a customer tenant in the CIPP system.
.DESCRIPTION
The Set-CIPPExcludeTenant function is used to add or remove a customer tenant from the exclusion list in the CIPP system.
Exclusion means that the tenant will be excluded from certain operations or processes in the system.
.PARAMETER CustomerTenantID
Specifies the ID of the customer tenant. If you are adding a tenant, this needs to be their default domain (contoso.onmicrosoft.com), if you are
excluding a tenant this needs to be the tenant ID Guid (1fefeb73-0947-4803-a720-92be0e9a7d8e)
.PARAMETER AddExclusion
Indicates whether to add the customer tenant to the exclusion list. This switch cannot be used together with the RemoveExclusion switch.
.PARAMETER RemoveExclusion
Indicates whether to remove the customer tenant from the exclusion list. This switch cannot be used together with the AddExclusion switch.
.EXAMPLE
Set-CIPPExcludeTenant -CustomerTenantID "1fefeb73-0947-4803-a720-92be0e9a7d8e" -AddExclusion
Adds the customer tenant with ID "1fefeb73-0947-4803-a720-92be0e9a7d8e" to the exclusion list.
.EXAMPLE
Set-CIPPExcludeTenant -CustomerTenantID "contoso.onmicrosoft.com" -RemoveExclusion
Removes the customer tenant with ID "contoso.onmicrosoft.com" from the exclusion list.
#>
function Set-CIPPExcludeTenant {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$CustomerTenantID,
[Parameter()]
[switch]$AddExclusion,
[Parameter()]
[switch]$RemoveExclusion
)

# Ensure only one of the switches is used
if ($AddExclusion -and $RemoveExclusion) {
throw "You cannot use both -AddExclusion and -RemoveExclusion switches at the same time."
}

if (-not $AddExclusion -and -not $RemoveExclusion) {
throw "You must specify either -AddExclusion or -RemoveExclusion switch."
}

$endpoint = "/api/execexcludetenant"

if ($RemoveExclusion) {
$params = @{
TenantFilter = $CustomerTenantID
RemoveExclusion = $true
}
Write-Verbose "Removing Tenant $CustomerTenantID from the exclusion list."
Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params
} else {
$params = @{
AddExclusion = $true
}
$body = @{
value = $CustomerTenantID
}
Write-Verbose "Adding Tenant $CustomerTenantID to the exclusion list."
Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params -Body $body -Method POST
}
}
52 changes: 52 additions & 0 deletions CIPPAPIModule/public/CIPP/Settings/Set-CIPPPasswordSettings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<#
.SYNOPSIS
Sets or gets the CIPP password settings.
.DESCRIPTION
The Set-CIPPPasswordSettings function is used to view the password settings for CIPP or to set them.
.PARAMETER Type
Specifies the type of password settings to be set. Valid values are "Correct-Battery-Horse" and "Classic".
.PARAMETER List
Specifies whether to list the current password settings. If set to $true, the function will retrieve the current password settings.
.EXAMPLE
Set-CIPPPasswordSettings -Type "Correct-Battery-Horse"
Sets the password settings to "Correct-Battery-Horse".
.EXAMPLE
Set-CIPPPasswordSettings -List $true
Lists the current password settings.
#>

function Set-CIPPPasswordSettings {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[ValidateSet(
"Correct-Battery-Horse",
"Classic"
)]
[string]$Type,
[Parameter(Mandatory = $false)]
[bool]$List
)

Write-Verbose "Getting CIPP Password Settings"

$endpoint = "/api/execpasswordconfig"

if ($List) {
$params = @{
List = "true"
}
Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params
} else {
$body = @{
passwordType = $Type
}
Invoke-CIPPRestMethod -Endpoint $endpoint -Body $body -Method "POST"
}
}
24 changes: 18 additions & 6 deletions CIPPAPIModule/public/Email-Exchange/Get-CIPPMailboxes.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
<#
.SYNOPSIS
Retrieves a list of mailboxes for a specific customer tenant.
Retrieves a list of mailboxes for a specified customer tenant ID.
.DESCRIPTION
The Get-CIPPMailboxes function retrieves a list of mailboxes for a specific customer tenant by making a REST API call to the "/api/ListMailboxes" endpoint.
The Get-CIPPMailboxes function retrieves a list of mailboxes for a specified customer tenant ID. It can also include soft-deleted mailboxes if the -SoftDeletedMailboxes switch is used.
.PARAMETER CustomerTenantID
The ID of the customer tenant for which to retrieve the mailbox list.
Specifies the customer tenant ID for which to retrieve the mailbox list.
.PARAMETER SoftDeletedMailboxes
Indicates whether to include soft-deleted mailboxes in the result. By default, this parameter is set to $false.
.EXAMPLE
Get-CIPPMailboxes -CustomerTenantID "7ced1621-b8f7-4231-868c-bc6b1a2f1778"
Retrieves the mailbox list for the customer tenant with the ID "7ced1621-b8f7-4231-868c-bc6b1a2f1778".
Get-CIPPMailboxes -CustomerTenantID "contoso.onmicrosoft.com"
Retrieves the list of mailboxes for the "contoso.onmicrosoft.com" tenant.
.EXAMPLE
Get-CIPPMailboxes -CustomerTenantID "contoso.onmicrosoft.com" -SoftDeletedMailboxes
Retrieves the list of soft-deleted mailboxes for the "contoso.onmicrosoft.com" tenant.
#>

function Get-CIPPMailboxes {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$CustomerTenantID
[string]$CustomerTenantID,
[Parameter(Mandatory = $false)]
[switch]$SoftDeletedMailboxes
)

Write-Verbose "Getting Mailbox List for $CustomerTenantID"
$endpoint = "/api/ListMailboxes"
$params = @{
tenantfilter = $CustomerTenantID
}
if ($SoftDeletedMailboxes) {
$params.Add("SoftDeletedMailbox", "true")
}
Invoke-CIPPRestMethod -Endpoint $endpoint -Params $params
}
Loading

0 comments on commit 9f94a58

Please sign in to comment.