Skip to content

Commit

Permalink
Merge pull request #9 from BNWEIN/Dev
Browse files Browse the repository at this point in the history
Added some example scripts
  • Loading branch information
BNWEIN authored Jun 28, 2024
2 parents 9f94a58 + 84a160d commit 7eff17b
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 25 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.2'
ModuleVersion = '1.1.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
2 changes: 1 addition & 1 deletion CIPPAPIModule/public/Invoke-CIPPRestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Invoke-CIPPRestMethod {
}
Write-Verbose "$Method [ $($UriBuilder.ToString()) ]"

$response = Invoke-RestMethod @Request -ConnectionTimeoutSeconds 600
$response = Invoke-RestMethod @Request
return $response

}
36 changes: 19 additions & 17 deletions Docs/Set-CIPPMailboxForwarding.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
# Set-CIPPMailboxForwarding
## SYNOPSIS

Set-CIPPMailboxForwarding [-CustomerTenantID] <string> [-UserID] <string> [[-DisableForwarding] <bool>] [[-ForwardExternalEmailAddress] <string>] [[-ForwardInternalEmailAddress] <string>] [[-KeepCopy] <bool>] [<CommonParameters>]

Sets mailbox forwarding for a user.
## DESCRIPTION

The Set-CIPPMailboxForwarding function sets mailbox forwarding for a user. It allows you to specify the customer tenant ID, user ID, and various forwarding options such as external and internal email addresses, disabling forwarding, and keeping a copy of forwarded emails.
# PARAMETERS

## **-CustomerTenantID**
> ![Foo](https://img.shields.io/badge/Type-string-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-TRUE-Red?) \
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-TRUE-Red?) \
The ID of the customer tenant.

## **-UserID**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-TRUE-Red?) \
The ID of the user whose mailbox forwarding needs to be set.

## **-DisableForwarding**
> ![Foo](https://img.shields.io/badge/Type-bool-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
> ![Foo](https://img.shields.io/badge/Type-Boolean-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) ![Foo](https://img.shields.io/badge/DefaultValue-False-Blue?color=5547a8)\
Specifies whether to disable mailbox forwarding. By default, it is set to $false.

## **-ForwardExternalEmailAddress**
> ![Foo](https://img.shields.io/badge/Type-string-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The external email address to forward emails to.

## **-ForwardInternalEmailAddress**
> ![Foo](https://img.shields.io/badge/Type-string-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The internal email address to forward emails to. This parameter accepts an array of email addresses.

## **-KeepCopy**
> ![Foo](https://img.shields.io/badge/Type-bool-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \

## **-UserID**
> ![Foo](https://img.shields.io/badge/Type-string-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-TRUE-Red?) \
> ![Foo](https://img.shields.io/badge/Type-Boolean-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) ![Foo](https://img.shields.io/badge/DefaultValue-False-Blue?color=5547a8)\
Specifies whether to keep a copy of forwarded emails. By default, it is set to $false.

#### EXAMPLE 1
```powershell
PS > Set-CIPPMailboxForwarding -CustomerTenantID "contoso.onmicrosoft.com" -UserID "john.doe@contoso.onmicrosoft.com" -ForwardExternalEmailAddress "john.doe@example.com" -KeepCopy $true
```


70 changes: 70 additions & 0 deletions Example Scripts/Get-AllTenants-Licenses.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<#
.SYNOPSIS
This script retrieves a list of tenants and their licenses using the CIPP API.
.DESCRIPTION
The script prompts the user to enter the CIPP API URL, client ID, client secret, and tenant ID.
It then imports the CIPPAPIModule and sets the CIPP API details using the provided inputs.
The script retrieves a list of tenants using the Get-CIPPTenants function.
For each tenant, it retrieves the licenses using the Get-CIPPLicenses function.
The script creates a custom object for each license and outputs the results.
Finally, it exports the results to a CSV file and opens it using the default application.
.PARAMETER CIPPAPIUrl
The URL of the CIPP API.
.PARAMETER CIPPClientID
The client ID for accessing the CIPP API.
.PARAMETER CIPPClientSecret
The client secret for accessing the CIPP API.
.PARAMETER TenantId
The ID of the tenant.
.EXAMPLE
.\Get-AllTenants-Licenses.ps1
.NOTES
This script requires the CIPPAPIModule to be installed.
#>

$CIPPAPIUrl = Read-Host "Enter the CIPP API URL"
$CIPPClientID = Read-Host "Enter the CIPP API Client ID"
$CIPPClientSecret = Read-Host "Enter the CIPP API Client Secret"
$TenantId = Read-Host "Enter the Tenant ID"

Import-Module CIPPAPIModule
Set-CIPPAPIDetails -CIPPClientID $CIPPClientID -CIPPClientSecret $CIPPClientSecret -CIPPAPIUrl $CIPPAPIUrl -TenantId $TenantId

Write-Output "Getting List of tenants"
$tenantsList = Get-CIPPTenants
Write-Output "Getting all customer licenses - This can take a few minutes..."
$CustomerLicenses = $tenantsList.defaultDomainName | ForEach-Object -Parallel {
Import-Module CIPPAPIModule
Set-CIPPAPIDetails -TenantID $using:TenantId -CIPPClientID $using:CIPPClientID -CIPPClientSecret $using:CIPPClientSecret -CIPPAPIUrl $using:CIPPAPIUrl
$tenant = $_
$Licenses = Get-CIPPLicenses -CustomerTenantID $tenant
foreach ($License in $Licenses) {
[PSCustomObject]@{
Tenant = $tenant
License = $License.License
CountUsed = $License.CountUsed
CountAvailable = $License.CountAvailable
TotalLicenses = $License.TotalLicenses
skuid = $License.skuid
skuPartNumber = $License.skuPartNumber
}
}
} -ThrottleLimit 5

if ($null -eq $CustomerLicenses) {
exit
}

$filename = "CustomerLicenses" + (Get-Date -Format "yyyy-MM-dd") + ".csv"
$filepath = "$env:TEMP\$($filename)"

$CustomerLicenses | Export-CSV -Path $filepath

Start-Process -FilePath $filepath
69 changes: 69 additions & 0 deletions Example Scripts/Get-AllTenants-SharedMailboxesEnabledAccount.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<#
.SYNOPSIS
This script retrieves a list of tenants and their shared mailboxes with account enabled using the CIPP API.
.DESCRIPTION
The script prompts the user to enter the CIPP API URL, client ID, client secret, and tenant ID. It then imports the CIPPAPIModule and sets the CIPP API details using the provided inputs.
The script retrieves a list of tenants using the Get-CIPPTenants function from the CIPPAPIModule. It then iterates through each tenant in parallel and retrieves the shared mailboxes with account enabled using the Get-CIPPEnabledSharedMailboxe function from the CIPPAPIModule. For each shared mailbox, it creates a custom object with properties such as Tenant, UserPrincipalName, DisplayName, GivenName, Surname, AccountEnabled, and onPremisesSyncEnabled.
If no shared mailboxes with account enabled are found, the script exits. Otherwise, it exports the data to a CSV file with a filename based on the current date and saves it to the user's temporary folder. Finally, it opens the CSV file using the default application associated with CSV files.
.PARAMETER CIPPAPIUrl
The URL of the CIPP API.
.PARAMETER CIPPClientID
The client ID for accessing the CIPP API.
.PARAMETER CIPPClientSecret
The client secret for accessing the CIPP API.
.PARAMETER TenantId
The ID of the tenant.
.EXAMPLE
PS C:\> .\Get-AllTenants-SharedMailboxesEnabledAccount.ps1
.NOTES
This script requires the CIPPAPIModule to be installed.
#>

$CIPPAPIUrl = Read-Host "Enter the CIPP API URL"
$CIPPClientID = Read-Host "Enter the CIPP API Client ID"
$CIPPClientSecret = Read-Host "Enter the CIPP API Client Secret"
$TenantId = Read-Host "Enter the Tenant ID"

Import-Module CIPPAPIModule
Set-CIPPAPIDetails -CIPPClientID $CIPPClientID -CIPPClientSecret $CIPPClientSecret -CIPPAPIUrl $CIPPAPIUrl -TenantId $TenantId

Write-Output "Getting List of tenants"
$tenantsList = Get-CIPPTenants
Write-Output "Getting all shared mailboxes with account enabled - This can take a few minutes..."
$SharedMailboxesEnabled = $tenantsList.defaultDomainName | ForEach-Object -Parallel {
Import-Module CIPPAPIModule
Set-CIPPAPIDetails -TenantID $using:TenantId -CIPPClientID $using:CIPPClientID -CIPPClientSecret $using:CIPPClientSecret -CIPPAPIUrl $using:CIPPAPIUrl
$tenant = $_
$SharedMailboxes = Get-CIPPEnabledSharedMailboxe -CustomerTenantID $tenant
foreach ($mailbox in $SharedMailboxes) {
[PSCustomObject]@{
Tenant = $tenant
UserPrincipalName = $mailbox.UserPrincipalName
DisplayName = $mailbox.DisplayName
GivenName = $mailbox.GivenName
Surname = $mailbox.Surname
AccountEnabled = $mailbox.AccountEnabled
onPremisesSyncEnabled = $mailbox.onPremisesSyncEnabled
}
}
} -ThrottleLimit 5

if ($null -eq $SharedMailboxesEnabled) {
exit
}

$filename = "SharedMailboxesAccountEnabled" + (Get-Date -Format "yyyy-MM-dd") + ".csv"
$filepath = "$env:TEMP\$($filename)"

$SharedMailboxesEnabled | Export-CSV -Path $filepath

Start-Process -FilePath $filepath
71 changes: 71 additions & 0 deletions Example Scripts/Get-AllTenants-SoftDeletedMailboxes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<#
.SYNOPSIS
This script retrieves a list of soft deleted mailboxes for all tenants using the CIPP API.
.DESCRIPTION
The script prompts the user to enter the CIPP API URL, client ID, client secret, and tenant ID. It then imports the CIPPAPIModule and sets the CIPP API details using the provided inputs.
The script retrieves a list of tenants using the Get-CIPPTenants function and then retrieves the soft deleted mailboxes for each tenant in parallel using the Get-CIPPMailboxes function. The retrieved mailbox information is stored in a custom object and exported to a CSV file.
.PARAMETER CIPPAPIUrl
The URL of the CIPP API.
.PARAMETER CIPPClientID
The client ID for accessing the CIPP API.
.PARAMETER CIPPClientSecret
The client secret for accessing the CIPP API.
.PARAMETER TenantId
The ID of the tenant.
.OUTPUTS
SoftDeletedMailboxes.csv - A CSV file containing the soft deleted mailbox information for all tenants.
.EXAMPLE
PS C:\> .\Get-AllTenants-SoftDeletedMailboxes.ps1
.NOTES
This script requires the CIPPAPIModule to be installed.
#>

$CIPPAPIUrl = Read-Host "Enter the CIPP API URL"
$CIPPClientID = Read-Host "Enter the CIPP API Client ID"
$CIPPClientSecret = Read-Host "Enter the CIPP API Client Secret"
$TenantId = Read-Host "Enter the Tenant ID"

Import-Module CIPPAPIModule
Set-CIPPAPIDetails -CIPPClientID $CIPPClientID -CIPPClientSecret $CIPPClientSecret -CIPPAPIUrl $CIPPAPIUrl -TenantId $TenantId

Write-Output "Getting List of tenants"
$tenantsList = Get-CIPPTenants
Write-Output "Getting all customers soft deleted mailboxes - This can take a few minutes..."
$DeletedMailboxes = $tenantsList.defaultDomainName | ForEach-Object -Parallel {
Import-Module CIPPAPIModule
Set-CIPPAPIDetails -TenantID $using:TenantId -CIPPClientID $using:CIPPClientID -CIPPClientSecret $using:CIPPClientSecret -CIPPAPIUrl $using:CIPPAPIUrl
$tenant = $_
$Deleted = Get-CIPPMailboxes -CustomerTenantID $tenant -SoftDeletedMailboxes
foreach ($mailbox in $Deleted) {
[PSCustomObject]@{
Tenant = $tenant
MailBoxDeletedDate = $mailbox.WhenSoftDeleted
DisplayName = $mailbox.DisplayName
UserPrincipalName = $mailbox.UPN
PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
MailboxType = $mailbox.RecipientType
MailboxStatus = $mailbox.RecipientTypeDetails
}
}
} -ThrottleLimit 5

if ($null -eq $DeletedMailboxes) {
exit
}

$filename = "SoftDeletedMailboxes" + (Get-Date -Format "yyyy-MM-dd") + ".csv"
$filepath = "$env:TEMP\$($filename)"

$DeletedMailboxes | Export-CSV -Path $filepath

Start-Process -FilePath $filepath
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ Get-CIPPLogs
- [Get-CIPPDevices](./Docs/Get-CIPPDevices.md)
## Identity
- Administration
- [Devices](./Docs/Devices.md)
- [Groups](./Docs/Groups.md)
- [Users](./Docs/Users.md)
- [Get-CIPPRoles](./Docs/Get-CIPPRoles.md)
- Reports
- [Get-CIPPBasicAuth](./Docs/Get-CIPPBasicAuth.md)
Expand Down Expand Up @@ -236,9 +233,6 @@ Get-CIPPLogs
- [Get-CIPPTeamsVoice](./Docs/Get-CIPPTeamsVoice.md)
## Tenant
- Administration
- [Alerts](./Docs/Alerts.md)
- [Application Approval](./Docs/Application Approval.md)
- [Tenant](./Docs/Tenant.md)
- [Get-CIPPAppConsentReqs](./Docs/Get-CIPPAppConsentReqs.md)
- [Get-CIPPDomains](./Docs/Get-CIPPDomains.md)
- Conditional
Expand Down Expand Up @@ -324,6 +318,14 @@ Invoke-CIPPRestMethod -Endpoint '/api/adduser' -method 'POST' -Body @{ 'tenantID

This example sends a POST request to the '/api/adduser' endpoint with a Body 'tenantID' set to '11c11ab1-527a-1d29-l92e-76413h012s76' and 'DisplayName' set to 'Test User', 'UserName' set to 'testuser', 'AutoPassword' set to $true, 'FirstName' set to 'Test', 'LastName' set to 'User', 'Domain' set to 'M365x72601982.onmicrosoft.com'

## Example Scripts

Some example scripts can be found Below:

- [Get-AllTenants-Licenses.ps1](./Example%20Scripts/Get-AllTenants-Licenses.ps1)
- [Get-AllTenants-SharedMailboxesEnabledAccount.ps1](./Example%20Scripts/Get-AllTenants-SharedMailboxesEnabledAccount.ps1)
- [Get-AllTenants-SoftDeletedMailboxes.ps1](./Example%20Scripts/Get-AllTenants-SoftDeletedMailboxes.ps1)

## Special Thanks

Special thanks to [@KelvinTegelaar](https://github.com/KelvinTegelaar/), [@JohnDuprey](https://github.com/JohnDuprey/), [@rvdwegen](https://github.com/rvdwegen) and [@Jr7468](https://github.com/Jr7468/). I Could not have got this far without you!
Expand All @@ -332,3 +334,4 @@ Special thanks to [@KelvinTegelaar](https://github.com/KelvinTegelaar/), [@JohnD




0 comments on commit 7eff17b

Please sign in to comment.