From 077c47920e6527879dce877858b14e3ebdda9b50 Mon Sep 17 00:00:00 2001 From: chase-vgo <168204519+chase-vgo@users.noreply.github.com> Date: Thu, 11 Jul 2024 08:51:33 -0500 Subject: [PATCH 1/4] Righted wrongs --- .../public/CIPP/Core/Get-CIPPLogs.ps1 | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 b/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 index 7252a40..91ea51d 100644 --- a/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 +++ b/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 @@ -5,21 +5,52 @@ 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. +Get-CIPPLogs -Severity "Alert" -DateFilter "20240711" +Retrieves CIPP logs matching "alert" on 20240711 #> function Get-CIPPLogs { [CmdletBinding()] - Param() + Param( + $Severity, + $DateFilter + ) - Write-Verbose "Getting CIPP Logs" $endpoint = "/api/ListLogs" - - Invoke-CIPPRestMethod -Endpoint $endpoint + + if($Severity -or $DateFilter){ + + $Params = @{ + 'Filter' = $True + } + + if($Severity){ + $Params['Severity'] = $Severity + } + + if($DateFilter){ + $Params['DateFilter'] = $DateFilter + }else{ + $Params['DateFilter'] = (Get-Date -Format "yyyyMMdd") + } + + Write-Verbose "Getting CIPP Logs" + Invoke-CIPPRestMethod -Endpoint $endpoint -Param $Params + + }else{ + + Write-Verbose "Getting CIPP Logs" + Invoke-CIPPRestMethod -Endpoint $endpoint + + } } From fa28487f82cb5208975030874b3e9d2fae3f4bcd Mon Sep 17 00:00:00 2001 From: chase-vgo <168204519+chase-vgo@users.noreply.github.com> Date: Thu, 11 Jul 2024 08:52:42 -0500 Subject: [PATCH 2/4] Righted wrongs --- Docs/Get-CIPPLogs.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Docs/Get-CIPPLogs.md b/Docs/Get-CIPPLogs.md index f4a9962..2dec0de 100644 --- a/Docs/Get-CIPPLogs.md +++ b/Docs/Get-CIPPLogs.md @@ -5,8 +5,18 @@ Retrieves CIPP logs from the API. The Get-CIPPLogs function retrieves logs from the CIPP API by invoking the "/api/ListLogs" endpoint. # PARAMETERS +## Severity +Accepts any of: debug,info,warn,error,critical,alert. If DateFilter is not specified alongside, it assumes current date in local time. + +## DateFilter +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" +``` From e9a56a4653e039c418eee4f5e26741d9b253e586 Mon Sep 17 00:00:00 2001 From: chase-vgo <168204519+chase-vgo@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:24:28 -0500 Subject: [PATCH 3/4] Update Get-CIPPLogs.ps1 --- .../public/CIPP/Core/Get-CIPPLogs.ps1 | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 b/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 index 91ea51d..4023e13 100644 --- a/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 +++ b/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 @@ -22,35 +22,33 @@ Retrieves CIPP logs matching "alert" on 20240711 function Get-CIPPLogs { [CmdletBinding()] Param( - $Severity, - $DateFilter + [Parameter(Mandatory = $false)] + [ValidateSet( + "error", + "alert", + "debug", + "info", + "warn", + "critical" + )] + [string]$Severity, + + [Parameter(Mandatory = $false)] + [string]$DateFilter = (Get-Date -Format "yyyyMMdd") ) $endpoint = "/api/ListLogs" - if($Severity -or $DateFilter){ - $Params = @{ - 'Filter' = $True - } - - if($Severity){ - $Params['Severity'] = $Severity - } - - if($DateFilter){ - $Params['DateFilter'] = $DateFilter - }else{ - $Params['DateFilter'] = (Get-Date -Format "yyyyMMdd") - } - - Write-Verbose "Getting CIPP Logs" - Invoke-CIPPRestMethod -Endpoint $endpoint -Param $Params - - }else{ - - Write-Verbose "Getting CIPP Logs" - Invoke-CIPPRestMethod -Endpoint $endpoint + $Params = @{ + 'Filter' = $True + 'DateFilter' = $DateFilter + } + if($Severity){ + $Params['Severity'] = $Severity } + + Write-Verbose "Getting CIPP Logs" + Invoke-CIPPRestMethod -Endpoint $endpoint -Param $Params } From e5f8d21ce73c3f83d507e985da87be3caa79ad6f Mon Sep 17 00:00:00 2001 From: BNWEIN Date: Mon, 22 Jul 2024 15:17:41 +0100 Subject: [PATCH 4/4] Minor Fixes and Additional Functions Set-CIPPContact --- CIPPAPIModule/CIPPAPIModule.psd1 | 2 +- .../public/CIPP/Core/Get-CIPPLogs.ps1 | 1 + .../public/Email-Exchange/Set-CIPPContact.ps1 | 113 ++++++++++++++++++ .../Administration/Tenant/Get-CIPPTenants.ps1 | 4 +- Docs/Get-CIPPLogs.md | 12 +- Docs/Get-CIPPTenants.md | 2 +- Docs/Set-CIPPContact.md | 66 ++++++++++ ...lTenants-SharedMailboxesEnabledAccount.ps1 | 2 +- README.md | 9 +- Tools/Update-ModuleVersion.ps1 | 38 ++++++ 10 files changed, 238 insertions(+), 11 deletions(-) create mode 100644 CIPPAPIModule/public/Email-Exchange/Set-CIPPContact.ps1 create mode 100644 Docs/Set-CIPPContact.md create mode 100644 Tools/Update-ModuleVersion.ps1 diff --git a/CIPPAPIModule/CIPPAPIModule.psd1 b/CIPPAPIModule/CIPPAPIModule.psd1 index 6c08e31..bb3010f 100644 --- a/CIPPAPIModule/CIPPAPIModule.psd1 +++ b/CIPPAPIModule/CIPPAPIModule.psd1 @@ -12,7 +12,7 @@ RootModule = 'CIPPAPIModule.psm1' # Version number of this module. -ModuleVersion = '1.1.4' +ModuleVersion = '1.1.5' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 b/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 index 4023e13..3e38f3f 100644 --- a/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 +++ b/CIPPAPIModule/public/CIPP/Core/Get-CIPPLogs.ps1 @@ -15,6 +15,7 @@ Date in "yyyyMMdd" format. This should be in the time zone of your CIPP instance Get-CIPPLogs Retrieves CIPP logs from the API. +.EXAMPLE Get-CIPPLogs -Severity "Alert" -DateFilter "20240711" Retrieves CIPP logs matching "alert" on 20240711 #> diff --git a/CIPPAPIModule/public/Email-Exchange/Set-CIPPContact.ps1 b/CIPPAPIModule/public/Email-Exchange/Set-CIPPContact.ps1 new file mode 100644 index 0000000..221080c --- /dev/null +++ b/CIPPAPIModule/public/Email-Exchange/Set-CIPPContact.ps1 @@ -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 +} diff --git a/CIPPAPIModule/public/Tenant/Administration/Tenant/Get-CIPPTenants.ps1 b/CIPPAPIModule/public/Tenant/Administration/Tenant/Get-CIPPTenants.ps1 index 0c2c046..ce1aa58 100644 --- a/CIPPAPIModule/public/Tenant/Administration/Tenant/Get-CIPPTenants.ps1 +++ b/CIPPAPIModule/public/Tenant/Administration/Tenant/Get-CIPPTenants.ps1 @@ -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 { diff --git a/Docs/Get-CIPPLogs.md b/Docs/Get-CIPPLogs.md index 2dec0de..df6d359 100644 --- a/Docs/Get-CIPPLogs.md +++ b/Docs/Get-CIPPLogs.md @@ -5,18 +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 -## Severity +## **-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 + ## **-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 + #### EXAMPLE 1 ```powershell PS > Get-CIPPLogs ``` - -#### EXAMPLE 2 + #### EXAMPLE 2 ```powershell PS > Get-CIPPLogs -Severity "Alert" -DateFilter "20240711" ``` + diff --git a/Docs/Get-CIPPTenants.md b/Docs/Get-CIPPTenants.md index 7553b91..ec81fff 100644 --- a/Docs/Get-CIPPTenants.md +++ b/Docs/Get-CIPPTenants.md @@ -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 ``` diff --git a/Docs/Set-CIPPContact.md b/Docs/Set-CIPPContact.md new file mode 100644 index 0000000..eff5e71 --- /dev/null +++ b/Docs/Set-CIPPContact.md @@ -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. +``` + diff --git a/Example Scripts/Get-AllTenants-SharedMailboxesEnabledAccount.ps1 b/Example Scripts/Get-AllTenants-SharedMailboxesEnabledAccount.ps1 index 0010abc..e11806d 100644 --- a/Example Scripts/Get-AllTenants-SharedMailboxesEnabledAccount.ps1 +++ b/Example Scripts/Get-AllTenants-SharedMailboxesEnabledAccount.ps1 @@ -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 diff --git a/README.md b/README.md index 924c608..f48113a 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) @@ -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 @@ -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! \ No newline at end of file +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! diff --git a/Tools/Update-ModuleVersion.ps1 b/Tools/Update-ModuleVersion.ps1 new file mode 100644 index 0000000..4fbdc05 --- /dev/null +++ b/Tools/Update-ModuleVersion.ps1 @@ -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." + } +} \ No newline at end of file