From 7afd825cef86837f4c1f5ac0a767ad16b568fd98 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 11 May 2023 15:25:26 -0600 Subject: [PATCH 1/6] Create Remove-JCPolicy.ps1 --- .../Public/Policies/Remove-JCPolicy.ps1 | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 PowerShell/JumpCloud Module/Public/Policies/Remove-JCPolicy.ps1 diff --git a/PowerShell/JumpCloud Module/Public/Policies/Remove-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Remove-JCPolicy.ps1 new file mode 100644 index 000000000..9399bde39 --- /dev/null +++ b/PowerShell/JumpCloud Module/Public/Policies/Remove-JCPolicy.ps1 @@ -0,0 +1,104 @@ +Function Remove-JCPolicy () { + param + ( + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'ByID', + Position = 0, + HelpMessage = 'The PolicyID of the JumpCloud policy you wish to remove.')] + [Alias('_id', 'id')] + [String]$PolicyID, + [Parameter( + ValueFromPipelineByPropertyName, + ParameterSetName = 'Name', + HelpMessage = 'The Name of the JumpCloud policy you wish to remove.')] + [String]$Name, + [Parameter(HelpMessage = 'A SwitchParameter which suppresses the warning message when removing a JumpCloud Policy.')] + [Switch] + $force + ) + begin { + Write-Debug 'Verifying JCAPI Key' + if ($JCAPIKEY.length -ne 40) { + Connect-JCOnline + } + + if ($PsCmdlet.ParameterSetName -eq "Name") { + $policyHash = Get-JCPolicy | Select-Object Id, Name + } + + $deletedArray = @() + } + process { + switch ($PsCmdlet.ParameterSetName) { + ByID { + if (!$force) { + Write-Warning "Are you sure you wish to delete policy: $PolicyID ?" -WarningAction Inquire + + try { + $removePolicy = Remove-JcSdkPolicy -Id $PolicyID -ErrorAction Stop + $Status = 'Deleted' + } catch { + $Status = $_.ErrorDetails + } + + $FormattedResults = [PSCustomObject]@{ + 'Policy' = $PolicyID + 'Results' = $Status + } + } else { + try { + $removePolicy = Remove-JcSdkPolicy -Id $PolicyID -ErrorAction Stop + $Status = 'Deleted' + } catch { + $Status = $_.ErrorDetails + } + + $FormattedResults = [PSCustomObject]@{ + 'Policy' = $PolicyID + 'Results' = $Status + } + } + $deletedArray += $FormattedResults + } + Name { + # Check if Policy exists with given name + if ($policyHash.Name -ccontains ($Name)) { + $Policy = $policyHash | Where-Object Name -CEQ $Name + } else { + throw "Policy does not exist. Run 'Get-JCPolicy | Select-Object Name' to see a list of all your JumpCloud policies" + } + + if (!$force) { + + Write-Warning "Are you sure you wish to delete policy: $Name ?" -WarningAction Inquire + try { + $removePolicy = Remove-JcSdkPolicy -Id $Policy.id -ErrorAction Stop + $Status = 'Deleted' + } catch { + $Status = $_.ErrorDetails + } + $FormattedResults = [PSCustomObject]@{ + 'Policy' = $Policy.Name + 'Results' = $Status + } + } else { + try { + $removePolicy = Remove-JcSdkPolicy -Id $Policy.id -ErrorAction Stop + $Status = 'Deleted' + } catch { + $Status = $_.ErrorDetails + } + $FormattedResults = [PSCustomObject]@{ + 'Policy' = $Policy.Name + 'Results' = $Status + } + } + $deletedArray += $FormattedResults + } + } + } + end { + return $deletedArray + } +} \ No newline at end of file From 19b9aa25ca9f7b6c248d06ea22856f6d4b9e18a5 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 11 May 2023 15:25:30 -0600 Subject: [PATCH 2/6] Create Remove-JCPolicy.tests.ps1 --- .../Public/Policies/Remove-JCPolicy.tests.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 PowerShell/JumpCloud Module/Tests/Public/Policies/Remove-JCPolicy.tests.ps1 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/Remove-JCPolicy.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/Remove-JCPolicy.tests.ps1 new file mode 100644 index 000000000..fba8a8f65 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Remove-JCPolicy.tests.ps1 @@ -0,0 +1,26 @@ +Describe -Tag:('JCPolicy') 'Remove-JCPolicy 1.10' { + BeforeAll { Connect-JCOnline -JumpCloudApiKey:($PesterParams_ApiKey) -force | Out-Null } + It 'Remove Policy by PolicyID' { + # Create test policy for removal + $policyTemplates = Get-JcSdkPolicyTemplate + $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "rename_local_administrator_account_windows" } + $templateId = $policyTemplate.id + $stringPolicy = New-JCPolicy -Name "Pester - Remove Policy Test" -templateID $templateId -ADMINISTRATORSTRING "Test String" + + $DeletedPolicy = Remove-JCPolicy -Id $stringPolicy.Id -Force + $DeletedPolicy.results | Should -Be 'Deleted' + } + It 'Remove Policy by Name' { + # Create test policy for removal + $policyTemplates = Get-JcSdkPolicyTemplate + $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "rename_local_administrator_account_windows" } + $templateId = $policyTemplate.id + $stringPolicy = New-JCPolicy -Name "Pester - Remove Policy Test" -templateID $templateId -ADMINISTRATORSTRING "Test String" + + $DeletedPolicy = Remove-JCPolicy -Name $stringPolicy.Name -Force + $DeletedPolicy.results | Should -Be 'Deleted' + } + It "Remove Policy by Non-existant Name" { + $DeletedPolicy = { Remove-JCPolicy -Name "Pester - Fake Policy Test" -Force -ErrorAction Stop } | Should -Throw + } +} \ No newline at end of file From 297089cedc9e887ae33655a3f62f71c5a08fd4f1 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 11 May 2023 15:25:33 -0600 Subject: [PATCH 3/6] Update workflows.yml --- .circleci/workflows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 433cb05fb..5d627a52c 100755 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -49,7 +49,7 @@ parameters: PublishToPSGallery: description: "When `true` and when run against Master branch, this workflow will publish the latest code to PSGallery" type: boolean - default: false + default: true ManualModuleVersion: description: "When `true` the pipeline will use the Module Version specified in JumpCloud Module JumpCloud.psd1 file" type: boolean From c957d1cbe257b72ef6f7aff846e7b579e5dde18d Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 11 May 2023 21:35:54 +0000 Subject: [PATCH 4/6] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/JumpCloud.md | 5 +- .../JumpCloud Module/Docs/Remove-JCPolicy.md | 96 ++++++++++++ PowerShell/JumpCloud Module/JumpCloud.psd1 | 9 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 145 ++++++++++++++++++ PowerShell/ModuleChangelog.md | 22 +++ 5 files changed, 272 insertions(+), 5 deletions(-) create mode 100644 PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index 414e76a5d..b62174e08 100644 --- a/PowerShell/JumpCloud Module/Docs/JumpCloud.md +++ b/PowerShell/JumpCloud Module/Docs/JumpCloud.md @@ -2,7 +2,7 @@ Module Name: JumpCloud Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646 Download Help Link: https://github.com/TheJumpCloud/support/wiki -Help Version: 2.4.0 +Help Version: 2.5.0 Locale: en-US --- @@ -157,6 +157,9 @@ Removes a JumpCloud Command Result ### [Remove-JCCommandTarget](Remove-JCCommandTarget.md) Removes the association between a JumpCloud system or a JumpCloud system group from a JumpCloud command +### [Remove-JCPolicy](Remove-JCPolicy.md) +{{ Fill in the Synopsis }} + ### [Remove-JCRadiusReplyAttribute](Remove-JCRadiusReplyAttribute.md) Removes Radius reply attributes from a JumpCloud user group. diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md new file mode 100644 index 000000000..4d78b17f7 --- /dev/null +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md @@ -0,0 +1,96 @@ +--- +external help file: JumpCloud-help.xml +Module Name: JumpCloud +online version: https://github.com/TheJumpCloud/support/wiki/ +schema: 2.0.0 +--- + +# Remove-JCPolicy + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +### ByID +``` +Remove-JCPolicy [-PolicyID] [-force] [] +``` + +### Name +``` +Remove-JCPolicy [-Name ] [-force] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -force +A SwitchParameter which suppresses the warning message when removing a JumpCloud Policy. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +The Name of the JumpCloud policy you wish to remove. + +```yaml +Type: System.String +Parameter Sets: Name +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PolicyID +The PolicyID of the JumpCloud policy you wish to remove. + +```yaml +Type: System.String +Parameter Sets: ByID +Aliases: _id, id + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index fe020be06..49d37b426 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.psd1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psd1 @@ -3,7 +3,7 @@ # # Generated by: JumpCloud Solutions Architect Team # -# Generated on: 4/27/2023 +# Generated on: 5/11/2023 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '2.4.0' +ModuleVersion = '2.5.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -87,8 +87,9 @@ FunctionsToExport = 'Add-JCAssociation', 'Add-JCCommandTarget', 'New-JCImportTemplate', 'New-JCPolicy', 'New-JCRadiusServer', 'New-JCSystemGroup', 'New-JCUser', 'New-JCUserGroup', 'Remove-JCAssociation', 'Remove-JCCommand', 'Remove-JCCommandResult', - 'Remove-JCCommandTarget', 'Remove-JCRadiusReplyAttribute', - 'Remove-JCRadiusServer', 'Remove-JCSystem', 'Remove-JCSystemGroup', + 'Remove-JCCommandTarget', 'Remove-JCPolicy', + 'Remove-JCRadiusReplyAttribute', 'Remove-JCRadiusServer', + 'Remove-JCSystem', 'Remove-JCSystemGroup', 'Remove-JCSystemGroupMember', 'Remove-JCSystemUser', 'Remove-JCUser', 'Remove-JCUserGroup', 'Remove-JCUserGroupMember', 'Send-JCPasswordReset', 'Set-JCCommand', 'Set-JCOrganization', diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index c250d4c50..e4969a223 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -12726,6 +12726,151 @@ PS C:\> New-JCPolicy -TemplateName darwin_Login_Window_Text -Values $policyV + + + Remove-JCPolicy + Remove + JCPolicy + + {{ Fill in the Synopsis }} + + + + {{ Fill in the Description }} + + + + Remove-JCPolicy + + force + + A SwitchParameter which suppresses the warning message when removing a JumpCloud Policy. + + + System.Management.Automation.SwitchParameter + + + False + + + Name + + The Name of the JumpCloud policy you wish to remove. + + System.String + + System.String + + + None + + + + Remove-JCPolicy + + PolicyID + + The PolicyID of the JumpCloud policy you wish to remove. + + System.String + + System.String + + + None + + + force + + A SwitchParameter which suppresses the warning message when removing a JumpCloud Policy. + + + System.Management.Automation.SwitchParameter + + + False + + + + + + force + + A SwitchParameter which suppresses the warning message when removing a JumpCloud Policy. + + System.Management.Automation.SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + Name + + The Name of the JumpCloud policy you wish to remove. + + System.String + + System.String + + + None + + + PolicyID + + The PolicyID of the JumpCloud policy you wish to remove. + + System.String + + System.String + + + None + + + + + + System.String + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> {{ Add example code here }} + + {{ Add example description here }} + + + + + + Online Version: + https://github.com/TheJumpCloud/support/wiki/ + + + Remove-JCRadiusReplyAttribute diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index f8c40a5c0..f64c6170a 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,3 +1,25 @@ +## 2.5.0 + +Release Date: May 11, 2023 + +#### RELEASE NOTES + +``` +{{Fill in the Release Notes}} +``` + +#### FEATURES: + +{{Fill in the Features}} + +#### IMPROVEMENTS: + +{{Fill in the Improvements}} + +#### BUG FIXES: + +{{Fill in the Bug Fixes}} + ## 2.4.0 Release Date: May 1, 2023 From 0b5a3f5c3d90bb5377781983e4476f04e4d647d0 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 11 May 2023 15:42:24 -0600 Subject: [PATCH 5/6] Update changelog/docs --- PowerShell/JumpCloud Module/Docs/JumpCloud.md | 2 +- .../JumpCloud Module/Docs/Remove-JCPolicy.md | 20 +++++++++++-------- PowerShell/ModuleChangelog.md | 12 ++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index b62174e08..a52d2a0f4 100644 --- a/PowerShell/JumpCloud Module/Docs/JumpCloud.md +++ b/PowerShell/JumpCloud Module/Docs/JumpCloud.md @@ -158,7 +158,7 @@ Removes a JumpCloud Command Result Removes the association between a JumpCloud system or a JumpCloud system group from a JumpCloud command ### [Remove-JCPolicy](Remove-JCPolicy.md) -{{ Fill in the Synopsis }} +Removes a JumpCloud Policy ### [Remove-JCRadiusReplyAttribute](Remove-JCRadiusReplyAttribute.md) Removes Radius reply attributes from a JumpCloud user group. diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md index 4d78b17f7..a7f960093 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Remove-JCPolicy ## SYNOPSIS -{{ Fill in the Synopsis }} +Removes a JumpCloud Policy ## SYNTAX @@ -23,16 +23,23 @@ Remove-JCPolicy [-Name ] [-force] [] ``` ## DESCRIPTION -{{ Fill in the Description }} +The Remove-JCPolicy function will remove a JumpCloud Policy from the JumpCloud organization. ## EXAMPLES ### Example 1 ```powershell -PS C:\> {{ Add example code here }} +PS C:\> Remove-JCPolicy -Name "Allow The Use of Biometrics" ``` -{{ Add example description here }} +This will remove the JumpCloud Policy with the name Allow The Use of Biometrics + +### Example 2 +```powershell +PS C:\> Remove-JCPolicy -PolicyID "645bea14b069dd0001bbe232" +``` + +This will remove the JumpCloud Policy by its corresponding ID ## PARAMETERS @@ -43,7 +50,6 @@ A SwitchParameter which suppresses the warning message when removing a JumpCloud Type: System.Management.Automation.SwitchParameter Parameter Sets: (All) Aliases: - Required: False Position: Named Default value: None @@ -58,7 +64,6 @@ The Name of the JumpCloud policy you wish to remove. Type: System.String Parameter Sets: Name Aliases: - Required: False Position: Named Default value: None @@ -73,7 +78,6 @@ The PolicyID of the JumpCloud policy you wish to remove. Type: System.String Parameter Sets: ByID Aliases: _id, id - Required: True Position: 0 Default value: None @@ -93,4 +97,4 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ### System.Object ## NOTES -## RELATED LINKS +## RELATED LINKS \ No newline at end of file diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index f64c6170a..a5eb268d3 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -5,20 +5,12 @@ Release Date: May 11, 2023 #### RELEASE NOTES ``` -{{Fill in the Release Notes}} +New Policy Function, Remove-JCPolicy added to the module ``` #### FEATURES: -{{Fill in the Features}} - -#### IMPROVEMENTS: - -{{Fill in the Improvements}} - -#### BUG FIXES: - -{{Fill in the Bug Fixes}} +Remove-JCPolicy added, remove existing JumpCloud Policies programmatically ## 2.4.0 From f0aae8d7435de9ec0417c9e9cf86b620c7416a2d Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 11 May 2023 21:50:29 +0000 Subject: [PATCH 6/6] Updating PowerShell Module;[skip ci] --- .../JumpCloud Module/Docs/Remove-JCPolicy.md | 7 ++++++- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 15 +++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md index a7f960093..70f1d4d18 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md @@ -50,6 +50,7 @@ A SwitchParameter which suppresses the warning message when removing a JumpCloud Type: System.Management.Automation.SwitchParameter Parameter Sets: (All) Aliases: + Required: False Position: Named Default value: None @@ -64,6 +65,7 @@ The Name of the JumpCloud policy you wish to remove. Type: System.String Parameter Sets: Name Aliases: + Required: False Position: Named Default value: None @@ -78,6 +80,7 @@ The PolicyID of the JumpCloud policy you wish to remove. Type: System.String Parameter Sets: ByID Aliases: _id, id + Required: True Position: 0 Default value: None @@ -97,4 +100,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ### System.Object ## NOTES -## RELATED LINKS \ No newline at end of file +## RELATED LINKS + +## RELATED LINKS diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 6b8318a2c..316898b4e 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.4.0 + 2.5.0.8557-202305112148 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index e4969a223..92bb0cfd6 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -12732,11 +12732,11 @@ PS C:\> New-JCPolicy -TemplateName darwin_Login_Window_Text -Values $policyV Remove JCPolicy - {{ Fill in the Synopsis }} + Removes a JumpCloud Policy - {{ Fill in the Description }} + The Remove-JCPolicy function will remove a JumpCloud Policy from the JumpCloud organization. @@ -12858,9 +12858,16 @@ PS C:\> New-JCPolicy -TemplateName darwin_Login_Window_Text -Values $policyV -------------------------- Example 1 -------------------------- - PS C:\> {{ Add example code here }} + PS C:\> Remove-JCPolicy -Name "Allow The Use of Biometrics" - {{ Add example description here }} + This will remove the JumpCloud Policy with the name Allow The Use of Biometrics + + + + -------------------------- Example 2 -------------------------- + PS C:\> Remove-JCPolicy -PolicyID "645bea14b069dd0001bbe232" + + This will remove the JumpCloud Policy by its corresponding ID