Skip to content

Commit

Permalink
Merge pull request #15 from BNWEIN/Dev
Browse files Browse the repository at this point in the history
Dev to Main
  • Loading branch information
BNWEIN authored Jul 22, 2024
2 parents 0ad6e2d + e5f8d21 commit 2cd7e61
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 12 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.4'
ModuleVersion = '1.1.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
40 changes: 35 additions & 5 deletions CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,51 @@ Retrieves CIPP logs from the API.
.DESCRIPTION
The Get-CIPPLogs function retrieves logs from the CIPP API by invoking the "/api/ListLogs" endpoint.
.PARAMETER None
This function does not accept any parameters.
.PARAMETER Severity
Accepts any of: debug,info,warn,error,critical,alert. If DateFilter is not specified alongside, it assumes current date in local time.
.PARAMETER DateFilter
Date in "yyyyMMdd" format. This should be in the time zone of your CIPP instance (default UTC).
.EXAMPLE
Get-CIPPLogs
Retrieves CIPP logs from the API.
.EXAMPLE
Get-CIPPLogs -Severity "Alert" -DateFilter "20240711"
Retrieves CIPP logs matching "alert" on 20240711
#>

function Get-CIPPLogs {
[CmdletBinding()]
Param()
Param(
[Parameter(Mandatory = $false)]
[ValidateSet(
"error",
"alert",
"debug",
"info",
"warn",
"critical"
)]
[string]$Severity,

[Parameter(Mandatory = $false)]
[string]$DateFilter = (Get-Date -Format "yyyyMMdd")
)

Write-Verbose "Getting CIPP Logs"
$endpoint = "/api/ListLogs"


$Params = @{
'Filter' = $True
'DateFilter' = $DateFilter
}

if($Severity){
$Params['Severity'] = $Severity
}

Invoke-CIPPRestMethod -Endpoint $endpoint
Write-Verbose "Getting CIPP Logs"
Invoke-CIPPRestMethod -Endpoint $endpoint -Param $Params
}
113 changes: 113 additions & 0 deletions CIPPAPIModule/public/Email-Exchange/Set-CIPPContact.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<#
.SYNOPSIS
Modifies a contact in the CIPP API.
.DESCRIPTION
The Set-CIPPContact function is used to edit a contact in the CIPP API. It allows you to modify various properties of the contact, such as display name, email address, first name, last name, job title, address, phone numbers, etc.
.PARAMETER CustomerTenantID
The ID of the customer tenant where the contact belongs.
.PARAMETER ContactID
The ID of the contact to be edited.
.PARAMETER DisplayName
The new display name for the contact. If not provided, the existing display name will be used.
.PARAMETER ExternalEmailAddress
The new external email address for the contact. If not provided, the existing email address will be used.
.PARAMETER FirstName
The new first name for the contact. If not provided, the existing first name will be used.
.PARAMETER LastName
The new last name for the contact. If not provided, the existing last name will be used.
.PARAMETER JobTitle
The new job title for the contact. If not provided, the existing job title will be used.
.PARAMETER StreetAddress
The new street address for the contact. If not provided, the existing street address will be used.
.PARAMETER PostalCode
The new postal code for the contact. If not provided, the existing postal code will be used.
.PARAMETER City
The new city for the contact. If not provided, the existing city will be used.
.PARAMETER Country
The new country for the contact. If not provided, the existing country will be used. This must be a valid ISO 3166-1 alpha-2 country code.
.PARAMETER MobilePhone
The new mobile phone number for the contact. If not provided, the existing mobile phone number will be used.
.PARAMETER PhoneNumber
The new business phone number for the contact. If not provided, the existing business phone number will be used.
.EXAMPLE
Set-CIPPContact -CustomerTenantID "contoso.onmicrosoft.com" -ContactID "46200db7-45cd-447e-a7d9-1d2feb91bb10" -DisplayName "John Doe" -JobTitle "Manager"
This example edits the contact with ID "46200db7-45cd-447e-a7d9-1d2feb91bb10" in the customer tenant "contoso.onmicrosoft.com". It sets the display name to "John Doe" and the job title to "Manager". Other properties remain unchanged.
#>

function Set-CIPPContact {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$CustomerTenantID,
[Parameter(Mandatory = $true)]
[string]$ContactID,
[Parameter(Mandatory = $false)]
[string]$DisplayName,
[Parameter(Mandatory = $false)]
[string]$ExternalEmailAddress,
[Parameter(Mandatory = $false)]
[string]$FirstName,
[Parameter(Mandatory = $false)]
[string]$LastName,
[Parameter(Mandatory = $false)]
[string]$JobTitle,
[Parameter(Mandatory = $false)]
[string]$StreetAddress,
[Parameter(Mandatory = $false)]
[string]$PostalCode,
[Parameter(Mandatory = $false)]
[string]$City,
[Parameter(Mandatory = $false)]
[string]$Country,
[Parameter(Mandatory = $false)]
[string]$MobilePhone,
[Parameter(Mandatory = $false)]
[string]$PhoneNumber
)

Write-Verbose "Editing Contact in tenant: $CustomerTenantID"

$existingContact = Get-CIPPContacts -CustomerTenantID $CustomerTenantID -ContactID $ContactID

# Filter to get the mobile and business phone numbers from the phones collection
$existingMobilePhone = ($existingContact.phones | Where-Object { $_.type -eq 'mobile' }).number
$existingBusinessPhone = ($existingContact.phones | Where-Object { $_.type -eq 'business' }).number

$Endpoint = "/api/Editcontact"

$body = @{
tenantID = $CustomerTenantID
ContactID = $ContactID
DisplayName = $DisplayName ? $DisplayName : $existingContact.DisplayName
mail = $ExternalEmailAddress ? $ExternalEmailAddress : $existingContact.mail
firstName = $FirstName ? $FirstName : $existingContact.givenName
LastName = $LastName ? $LastName : $existingContact.surname
jobTitle = $JobTitle ? $JobTitle : $existingContact.jobTitle
Country = $Country ? $Country : $existingContact.addresses.CountryOrRegion
PostalCode = $PostalCode ? $PostalCode : $existingContact.addresses.postalcode
CompanyName = $CompanyName ? $CompanyName : $existingContact.companyName
StreetAddress = $StreetAddress ? $StreetAddress : $existingContact.addresses.street
MobilePhone = $MobilePhone ? $MobilePhone : $existingMobilePhone
BusinessPhone = $PhoneNumber ? $PhoneNumber : $existingBusinessPhone
City = $City ? $City : $existingContact.addresses.city
}

Invoke-CIPPRestMethod -Endpoint $Endpoint -Body $body -Method POST
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Indicates whether to clear the cache before retrieving the tenants. This paramet
Indicates whether to trigger a refresh before retrieving the tenants. This parameter is optional.
.EXAMPLE
Get-CIPPTenants -CustomerTenantID "7ced1621-b8f7-4231-868c-bc6b1a2f1778" -ClearCache
This example retrieves the list of CIPP tenants for the specified customer tenant ID and clears the cache before retrieving the tenants.
Get-CIPPTenants -CustomerTenantID "contoso.onmicrosoft.com" -ClearCache
This example retrieves the list of CIPP tenants for the specified customer tenant and clears the cache before retrieving the tenants.
#>
function Get-CIPPTenants {
Expand Down
14 changes: 13 additions & 1 deletion Docs/Get-CIPPLogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ Retrieves CIPP logs from the API.
The Get-CIPPLogs function retrieves logs from the CIPP API by invoking the "/api/ListLogs" endpoint.
# PARAMETERS

#### EXAMPLE 1
## **-Severity**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
Accepts any of: debug,info,warn,error,critical,alert. If DateFilter is not specified alongside, it assumes current date in local time.

## **-DateFilter**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) ![Foo](https://img.shields.io/badge/DefaultValue-(Get-Date -Format "yyyyMMdd")-Blue?color=5547a8)\
Date in "yyyyMMdd" format. This should be in the time zone of your CIPP instance (default UTC).

#### EXAMPLE 1
```powershell
PS > Get-CIPPLogs
```
#### EXAMPLE 2
```powershell
PS > Get-CIPPLogs -Severity "Alert" -DateFilter "20240711"
```

2 changes: 1 addition & 1 deletion Docs/Get-CIPPTenants.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Indicates whether to trigger a refresh before retrieving the tenants. This param

#### EXAMPLE 1
```powershell
PS > Get-CIPPTenants -CustomerTenantID "7ced1621-b8f7-4231-868c-bc6b1a2f1778" -ClearCache
PS > Get-CIPPTenants -CustomerTenantID "contoso.onmicrosoft.com" -ClearCache
```

66 changes: 66 additions & 0 deletions Docs/Set-CIPPContact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Set-CIPPContact
## SYNOPSIS
Modifies a contact in the CIPP API.
## DESCRIPTION
The Set-CIPPContact function is used to edit a contact in the CIPP API. It allows you to modify various properties of the contact, such as display name, email address, first name, last name, job title, address, phone numbers, etc.
# PARAMETERS

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

## **-ContactID**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-TRUE-Red?) \
The ID of the contact to be edited.

## **-DisplayName**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new display name for the contact. If not provided, the existing display name will be used.

## **-ExternalEmailAddress**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new external email address for the contact. If not provided, the existing email address will be used.

## **-FirstName**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new first name for the contact. If not provided, the existing first name will be used.

## **-LastName**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new last name for the contact. If not provided, the existing last name will be used.

## **-JobTitle**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new job title for the contact. If not provided, the existing job title will be used.

## **-StreetAddress**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new street address for the contact. If not provided, the existing street address will be used.

## **-PostalCode**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new postal code for the contact. If not provided, the existing postal code will be used.

## **-City**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new city for the contact. If not provided, the existing city will be used.

## **-Country**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new country for the contact. If not provided, the existing country will be used. This must be a valid ISO 3166-1 alpha-2 country code.

## **-MobilePhone**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new mobile phone number for the contact. If not provided, the existing mobile phone number will be used.

## **-PhoneNumber**
> ![Foo](https://img.shields.io/badge/Type-String-Blue?) ![Foo](https://img.shields.io/badge/Mandatory-FALSE-Green?) \
The new business phone number for the contact. If not provided, the existing business phone number will be used.

#### EXAMPLE 1
```powershell
PS > Set-CIPPContact -CustomerTenantID "contoso.onmicrosoft.com" -ContactID "46200db7-45cd-447e-a7d9-1d2feb91bb10" -DisplayName "John Doe" -JobTitle "Manager"
This example edits the contact with ID "46200db7-45cd-447e-a7d9-1d2feb91bb10" in the customer tenant "contoso.onmicrosoft.com". It sets the display name to "John Doe" and the job title to "Manager". Other properties remain unchanged.
```

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $SharedMailboxesEnabled = $tenantsList.defaultDomainName | ForEach-Object -Paral
Import-Module CIPPAPIModule
Set-CIPPAPIDetails -TenantID $using:TenantId -CIPPClientID $using:CIPPClientID -CIPPClientSecret $using:CIPPClientSecret -CIPPAPIUrl $using:CIPPAPIUrl
$tenant = $_
$SharedMailboxes = Get-CIPPEnabledSharedMailboxe -CustomerTenantID $tenant
$SharedMailboxes = Get-CIPPEnabledSharedMailboxes -CustomerTenantID $tenant
foreach ($mailbox in $SharedMailboxes) {
[PSCustomObject]@{
Tenant = $tenant
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Get-CIPPLogs
- [Get-CIPPUserMailboxDetails](./Docs/Get-CIPPUserMailboxDetails.md)
- [Get-CIPPUserMailboxRules](./Docs/Get-CIPPUserMailboxRules.md)
- [Set-CIPPCalendarPermissions](./Docs/Set-CIPPCalendarPermissions.md)
- [Set-CIPPContact](./Docs/Set-CIPPContact.md)
- [Set-CIPPConvertMailbox](./Docs/Set-CIPPConvertMailbox.md)
- [Set-CIPPCopyToSent](./Docs/Set-CIPPCopyToSent.md)
- [Set-CIPPEnableArchive](./Docs/Set-CIPPEnableArchive.md)
Expand Down Expand Up @@ -125,6 +126,9 @@ 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 @@ -243,6 +247,9 @@ 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 @@ -341,4 +348,4 @@ Some example scripts can be found Below:

## 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!
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!
38 changes: 38 additions & 0 deletions Tools/Update-ModuleVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function Update-ModuleVersion {
param (
[string]$FilePath = "..\CIPPAPIModule\CIPPAPIModule\CIPPAPIModule.psd1"
)

# Read the file contents
$content = Get-Content -Path $FilePath

# Find the line with ModuleVersion
$moduleVersionLine = $content | Where-Object { $_ -match "ModuleVersion\s*=\s*\'\d+\.\d+\.\d+\'" }

if ($moduleVersionLine) {
# Extract the version number
$version = $moduleVersionLine -replace "ModuleVersion\s*=\s*\'([0-9]+\.[0-9]+\.[0-9]+)\'.*", '$1'

# Split the version number into parts
$versionParts = $version -split '\.'

# Increment the patch version (third part)
$versionParts[2] = [int]$versionParts[2] + 1

# Create the new version string
$newVersion = "$($versionParts[0]).$($versionParts[1]).$($versionParts[2])"

# Replace the old version line with the new version line
$newContent = $content -replace "ModuleVersion\s*=\s*\'$version\'", "ModuleVersion = '$newVersion'"

# Backup the original file
Copy-Item -Path $FilePath -Destination "$FilePath.bak" -Force

# Write the new contents back to the file
Set-Content -Path $FilePath -Value $newContent

Write-Host "Module version updated to $newVersion"
} else {
Write-Host "ModuleVersion line not found in the file."
}
}

0 comments on commit 2cd7e61

Please sign in to comment.