From 2c2b16457cf5dcb47e99821f6a10f8bb5fec5ffc Mon Sep 17 00:00:00 2001 From: lucdekens Date: Fri, 1 Dec 2017 23:08:04 +0100 Subject: [PATCH] Add module rCisTag Module rCisTag provides CRUD functions for Tags, Tag Categories and Tag Assignments. The functions use the Cis REST API functions. This is a beta release (0.9.0), feedback welcome. --- Modules/rCisTag/MITLicense.txt | 21 + Modules/rCisTag/README.md | 15 + Modules/rCisTag/en-US/about_rCISTag.Help.txt | 26 + Modules/rCisTag/en-US/rCISTag-help.xml | 1793 ++++++++++++++++++ Modules/rCisTag/rCISTag.psd1 | Bin 0 -> 5838 bytes Modules/rCisTag/rCISTag.psm1 | 821 ++++++++ 6 files changed, 2676 insertions(+) create mode 100644 Modules/rCisTag/MITLicense.txt create mode 100644 Modules/rCisTag/README.md create mode 100644 Modules/rCisTag/en-US/about_rCISTag.Help.txt create mode 100644 Modules/rCisTag/en-US/rCISTag-help.xml create mode 100644 Modules/rCisTag/rCISTag.psd1 create mode 100644 Modules/rCisTag/rCISTag.psm1 diff --git a/Modules/rCisTag/MITLicense.txt b/Modules/rCisTag/MITLicense.txt new file mode 100644 index 0000000..b4eaf48 --- /dev/null +++ b/Modules/rCisTag/MITLicense.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) since 2015 Luc Dekens, Matt Boren + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Modules/rCisTag/README.md b/Modules/rCisTag/README.md new file mode 100644 index 0000000..4160fdc --- /dev/null +++ b/Modules/rCisTag/README.md @@ -0,0 +1,15 @@ +# rCisTag + +A module with cmdlets to provide CRUD functions to +* Tags +* Tag Categories +* Tag Assignments + +The cmdlets use the Cis REST API + +## History + +* Author : **Luc Dekens** +* Release : + * **0.9.0** First draft + \ No newline at end of file diff --git a/Modules/rCisTag/en-US/about_rCISTag.Help.txt b/Modules/rCisTag/en-US/about_rCISTag.Help.txt new file mode 100644 index 0000000..f3b393f --- /dev/null +++ b/Modules/rCisTag/en-US/about_rCISTag.Help.txt @@ -0,0 +1,26 @@ +TOPIC + about_rCISTag + +SHORT DESCRIPTION + The rCisTag module provides CRUD functions to work with vSphere Tags + +LONG DESCRIPTION + The CisTag module provides CRUD functions to work with vSphere Tags. + The functions in the module are based on the REST API + +NOTE + The module requires PowerShell 5.0 + +TROUBLESHOOTING NOTE + + + +EXAMPLES + Get-rCisTag + +KEYWORDS + + + +SEE ALSO + Place related topics here. \ No newline at end of file diff --git a/Modules/rCisTag/en-US/rCISTag-help.xml b/Modules/rCisTag/en-US/rCISTag-help.xml new file mode 100644 index 0000000..023f48c --- /dev/null +++ b/Modules/rCisTag/en-US/rCISTag-help.xml @@ -0,0 +1,1793 @@ + + + + + Connect-rCisServer + Connect + rCisServer + + Make a connection to the CIS service on the vCenter + + + + Make a connection to the CIS service on the vCenter. Credentials need to be provided. + + + + Connect-rCisServer + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Credential + + A PSCredential object with a user and password that is allowed to connect to the CIS service. + + PSCredential + + PSCredential + + + None + + + Fiddler + + Connects to a Fiddler instance on the station where the cmdlet is executed. Used for debugging purposes. + + + SwitchParameter + + + False + + + Proxy + + When the vCenter is located behind a proxy, specify the proxy. + + String + + String + + + None + + + Server + + The hostname of the vCenter + + String + + String + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + Connect-rCisServer + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Fiddler + + Connects to a Fiddler instance on the station where the cmdlet is executed. Used for debugging purposes. + + + SwitchParameter + + + False + + + Password + + The user's password + + String + + String + + + None + + + Proxy + + When the vCenter is located behind a proxy, specify the proxy. + + String + + String + + + None + + + Server + + The hostname of the vCenter + + String + + String + + + None + + + User + + The user to connect to the CIS service + + String + + String + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Credential + + A PSCredential object with a user and password that is allowed to connect to the CIS service. + + PSCredential + + PSCredential + + + None + + + Fiddler + + Connects to a Fiddler instance on the station where the cmdlet is executed. Used for debugging purposes. + + SwitchParameter + + SwitchParameter + + + False + + + Password + + The user's password + + String + + String + + + None + + + Proxy + + When the vCenter is located behind a proxy, specify the proxy. + + String + + String + + + None + + + Server + + The hostname of the vCenter + + String + + String + + + None + + + User + + The user to connect to the CIS service + + String + + String + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Management.Automation.PSCredential + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> Connect-rCisServer -Server 'vcsa.domain.org' -User 'administrator@vsphere.local' -Password 'vSphere1!' + + Connect to the CIS service on vCenter vcsa.domain.org with user administrator@vsphere.local + + + + Example 2 + PS C:\> Connect-rCisServer -Server 'vcsa.domain.org' -Credential $cred + + Connect to the CIS service on vCenter vcsa.domain.org with the PSCredential stored in $cred + + + + + + + + Disconnect-rCisServer + Disconnect + rCisServer + + Closes the open connection to the CIS REST API + + + + Closes the open connection to the Cis REST API on the host passed on the Server parameter. + + + + Disconnect-rCisServer + + Server + + The name of the server on which the Cis REST API was opened. + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Server + + The name of the server on which the Cis REST API was opened. + + String + + String + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> Disconnect-rCisServer -Server 'vcsa.domain.org' + + Closes the connection to the server vcsa.domain.org + + + + + + + + Get-rCisTag + Get + rCisTag + + Retrieves Tags from vCenter + + + + Return Tags found on the vCenter. + + + + Get-rCisTag + + Category + + The returned tags are restricted to the category with name passed on this parameter + + PSObject[] + + PSObject[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Name + + Return the tag(s) with this/these name(s) + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + Get-rCisTag + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Id + + Return the tag with the specific ID + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Category + + The returned tags are restricted to the category with name passed on this parameter + + PSObject[] + + PSObject[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Id + + Return the tag with the specific ID + + String[] + + String[] + + + None + + + Name + + Return the tag(s) with this/these name(s) + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Management.Automation.PSObject[] + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> Get-rCisTag -Name MyTag + + Return the tags that are named MyTag + + + + Example 2 + PS C:\> Get-rCisTag -Name MyTag -Category MyCategory + + Return the tags that are named MyTag in the category MyCategory + + + + Example 3 + PS C:\> Get-rCisTag -Id urn:vmomi:InventoryServiceTag:385c90a7-e4ad-49af-a0a5-66fc5fedb254:GLOBAL + + Return the tag with the Id urn:vmomi:InventoryServiceTag:385c90a7-e4ad-49af-a0a5-66fc5fedb254:GLOBAL + + + + Example 4 + PS C:\> Get-rCisTagCategory -Name MyCat | Get-rCisTag + + Return all the Tags in TagCategory MyCat + + + + Example 5 + PS C:\> Get-rCisTag -Name MyTag1,MyTag2 + + Return all the Tags named MyTag1 and MyTag2 + + + + + + + + Get-rCisTagAssignment + Get + rCisTagAssignment + + Return Tag assignments + + + + Return information about all or specific Tag assignments + + + + Get-rCisTagAssignment + + Entity + + Return Tag assignments made to this entity + + PSObject[] + + PSObject[] + + + None + + + Tag + + Return Tag assignments for this Tag + + PSObject[] + + PSObject[] + + + None + + + Category + + Return only Tag assignments for Tags from this specific Category + + PSObject[] + + PSObject[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Category + + Return only Tag assignments for Tags from this specific Category + + PSObject[] + + PSObject[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Entity + + Return Tag assignments made to this entity + + PSObject[] + + PSObject[] + + + None + + + Tag + + Return Tag assignments for this Tag + + PSObject[] + + PSObject[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Management.Automation.PSObject[] + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> Get-rCisTagAssignment + + Return all Tag assignments + + + + Example 2 + PS C:\> Get-rCisTagAssignment -Entity MyVM + + Return all Tag assignments to entity MyVM + + + + Example 3 + PS C:\> Get-rCisTagAssignment -Entity MyVM -Tag MyTag + + Return the Tag assignment to entity MyVM for a Tag with the name MyTag + + + + Example 4 + PS C:\> Get-rCisTagAssignment -Entity MyVM -Category MyCat + + Return all Tag assignments to entity MyVM with Tags from the Tag Category named MyCat + + + + Example 5 + PS C:\> Get-rCisTagAssignment -Category MyCat + + Return all Tag assignments for all Tags from the Tag Category MyCat + + + + Example 6 + PS C:\> Get-VM MyVM | Get-rCisTagAssignment + + Return all Tag assignments made to entity MyVM + + + + + + + + Get-rCisTagCategory + Get + rCisTagCategory + + Return one or more Tag Categories + + + + Return specific Tag Categories defined on the vCenter. The returned Tag Categories can be filtered by the parameters. + + + + Get-rCisTagCategory + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Id + + The Tag Category Id + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + Get-rCisTagCategory + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Name + + The name of the Tag Category + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Id + + The Tag Category Id + + String[] + + String[] + + + None + + + Name + + The name of the Tag Category + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> Get-rCisTagCategory + + Return all Tag Categories + + + + Example 2 + PS C:\> Get-rCisTagCategory -Name Cat1,Cat2 + + Return the Tag Categories named Cat1 and Cat2 + + + + Example 3 + PS C:\> Get-rCisTagCategory -Id urn:vmomi:InventoryServiceCategory:925d8ae1-6b6e-403a-9a12-e78e14b1cdd4:GLOBAL + + Return the Tag Category with Id urn:vmomi:InventoryServiceCategory:925d8ae1-6b6e-403a-9a12-e78e14b1cdd4:GLOBAL + + + + + + + + New-rCisTag + New + rCisTag + + Create a Tag + + + + Create a Tag in one or more Categories, optionally with a Description + + + + New-rCisTag + + Name + + The Name of the new Tag + + String[] + + String[] + + + None + + + Category + + The name of the Category in which to create the Tag + + PSObject + + PSObject + + + None + + + Description + + An optional Description for the Tag + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Category + + The name of the Category in which to create the Tag + + PSObject + + PSObject + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Description + + An optional Description for the Tag + + String + + String + + + None + + + Name + + The Name of the new Tag + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Management.Automation.PSObject + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> New-rCisTag -Name MyTag -Category MyCategory + + Creates a Tag named MyTag in the Category MyCategory + + + + Example 2 + PS C:\> New-rCisTag -Name MyTag + + Creates a Tag named MyTag in all Categories + + + + Example 3 + PS C:\> Get-rCisCategory -Name MyCategory | New-rCisTag -Name MyTag -Description 'Text' + + Creates a Tag named MyTag in the Category MyCategory. And add the Description 'Text' to the Tag. + + + + + + + + New-rCisTagAssignment + New + rCisTagAssignment + + Create a new Tag assignment to an Entity + + + + Create a Tag assignment to one more Entities + + + + New-rCisTagAssignment + + Tag + + The name of the Tag to assign to the entity + + String[] + + String[] + + + None + + + Entity + + The name of the Entity or the PowerCLI object for the entity + + PSObject[] + + PSObject[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Entity + + The name of the Entity or the PowerCLI object for the entity + + PSObject[] + + PSObject[] + + + None + + + Tag + + The name of the Tag to assign to the entity + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.Management.Automation.PSObject[] + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> New-rCisTagAssignment -Tag MyTag -Entity MyVM + + Assign the Tag MyTag to the entity MyVM + + + + Example 2 + PS C:\> Get-VM | New-rCisTagAssignment -Tag MyTag + + Assign the Tag MyTag to all VMs + + + + + + + + New-rCisTagCategory + New + rCisTagCategory + + Create a new Tag Category + + + + Creates a new Tag Category. The user can define the Cardinality of the Tag Catgeory (default Single), add a description to the Tag Category and specify for which entity types the Tag Category can be used. + + + + New-rCisTagCategory + + Name + + The name of the new Tag Category + + String[] + + String[] + + + None + + + Cardinality + + Defines the Cardinality of the Tags in this Tag Category. Possible values are Single (default) and Multiple. + + + Single + Multiple + + String + + String + + + None + + + Description + + A description that is attached to the Tag Category + + String + + String + + + None + + + EntityType + + The type of Entity/Entities to which Tags in this Tag Category can be attached. + + String[] + + String[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Cardinality + + Defines the Cardinality of the Tags in this Tag Category. Possible values are Single (default) and Multiple. + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Description + + A description that is attached to the Tag Category + + String + + String + + + None + + + EntityType + + The type of Entity/Entities to which Tags in this Tag Category can be attached. + + String[] + + String[] + + + None + + + Name + + The name of the new Tag Category + + String[] + + String[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + None + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> New-rCisTagCategory -Name MyCat + + Create a new Tag Category named MyCat + + + + Example 2 + PS C:\> New-rCisTagCategory -Name MyCat -Cardinality Multiple -Description 'My Category' + + Create a new Tag Category named MyCat, with a Cardinality of Multiple and a description. + + + + + + + + Remove-rCisTag + Remove + rCisTag + + Remove a Tag + + + + Remove one or more Tags from the environment + + + + Remove-rCisTag + + Tag + + {{Fill Tag Description}} + + PSObject[] + + PSObject[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + Remove-rCisTag + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + Id + + {{Fill Id Description}} + + String[] + + String[] + + + None + + + + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Tag + + {{Fill Tag Description}} + + PSObject[] + + PSObject[] + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + Id + + {{Fill Id Description}} + + String[] + + String[] + + + None + + + + + + System.Management.Automation.PSObject[] + + + + + + + + + + System.Object + + + + + + + + + + + + + + Example 1 + PS C:\> Remove-rCisTag -Name MyTag + + Remove the Tag named MyTag + + + + Example 2 + PS C:\> Remove-rCisTag -Name MyTag + + Remove the Tag named MyTag + + + + + + \ No newline at end of file diff --git a/Modules/rCisTag/rCISTag.psd1 b/Modules/rCisTag/rCISTag.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..a9099d9b4397c79fbc4db9a0aa39ad2317b2deba GIT binary patch literal 5838 zcmcJTT~8ZF6o%&-ssCXmE({g8Aqf$=s1(bD1_@{cg!b0>tE>8}*kGcnf4%Md%<(Y0 z_O4@_Aj|g7&dfRQ`93rM{rkcF?Y8vUc8R-kO?T%~H*yn=`fli2?%wrWTce?75_hZF zfotgb>%xkT=4@@ljrAFdTB@}Z?Qd!IRHKReLr?ssS^20dr1ML||g1&I`7AZRV&GL^t;GN|; zPstFx64&?ozRK`Cb;qK5FRmu(M0^+{*{U5r0|J(3SZ#~!ddUxxN+&gJzUkG1o?w$W0X>_Ew2ihC;R1+?^n_ZXb zWy|H)8lp4pZwlYBxc}*;8fU22MYk{OU|r-iE)RZPYbBm}3Kyc(*Y2Q?3(**89OYsC zNWAdhuH?dl@hI~@_M-Ph_BSkLnlGYb5}(T=*P?JH4oy!Fdnay3FBt$2Av@G(mg;)@ zq+V;$y60ZUseFKFPNa=|l;^ein_rEeO@%oT8lKp3Zo8r~i$D+6ABd;rur;=I(kb}rT zmT7kslV^(R-3?{4-QSYov)3{C)OrT0H2pc4cH(=b6t}OGDU4HlVj;ES1 zw^Z-mZj5#jN39gaVtmA$O1?qk)E)X8x&of)K#nL{?hP|20bhqZud3#NLbw%!Vd=bQf`>JS9ysw%6(Ph}lBX6IVMVv)Y zj=GZR1m|OHF>1+t$UsLz*09qA89SVVn9X+$*;zVXY{wi#8B`ba^I=4~DBX{d_jc@UsWhBll zF}p8YpYM~uN}fHp9!BgrEx}kkSB|lG{qr%BxAE);{TFL<*@|+!%XU2KjjGbSSCf-R^4= zc|K1K>1v`pV4CKH5XPaidina7M|S*#%QO}x_#}Py(C|j|MYTUL~ z%UE8}NtjH7_G|ol~pHl3gF}0?h*d$OHceY3 + + Set-StrictMode -Version 2 + + # You have already run this function + if ([System.Net.ServicePointManager]::CertificatePolicy.ToString() -eq 'IgnoreCerts') { Return } + + $Domain = [AppDomain]::CurrentDomain + $DynAssembly = New-Object System.Reflection.AssemblyName('IgnoreCerts') + $AssemblyBuilder = $Domain.DefineDynamicAssembly($DynAssembly, [System.Reflection.Emit.AssemblyBuilderAccess]::Run) + $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('IgnoreCerts', $false) + $TypeBuilder = $ModuleBuilder.DefineType('IgnoreCerts', 'AutoLayout, AnsiClass, Class, Public, BeforeFieldInit', [System.Object], [System.Net.ICertificatePolicy]) + $TypeBuilder.DefineDefaultConstructor('PrivateScope, Public, HideBySig, SpecialName, RTSpecialName') | Out-Null + $MethodInfo = [System.Net.ICertificatePolicy].GetMethod('CheckValidationResult') + $MethodBuilder = $TypeBuilder.DefineMethod($MethodInfo.Name, 'PrivateScope, Public, Virtual, HideBySig, VtableLayoutMask', $MethodInfo.CallingConvention, $MethodInfo.ReturnType, ([Type[]] ($MethodInfo.GetParameters() | % {$_.ParameterType}))) + $ILGen = $MethodBuilder.GetILGenerator() + $ILGen.Emit([Reflection.Emit.Opcodes]::Ldc_I4_1) + $ILGen.Emit([Reflection.Emit.Opcodes]::Ret) + $TypeBuilder.CreateType() | Out-Null + + # Disable SSL certificate validation + [System.Net.ServicePointManager]::CertificatePolicy = New-Object IgnoreCerts +} + +function Invoke-vCisRest{ + param ( + [String]$Method, + [String]$Request, + [PSObject]$Body + ) + + Process + { + Write-Verbose -Message "$($MyInvocation.MyCommand.Name)" + Write-Verbose -Message "`t$($PSCmdlet.ParameterSetName)" + Write-Verbose -Message "`tCalled from $($stack = Get-PSCallStack; $stack[1].Command) at $($stack[1].Location)" + + Disable-SSLValidation + + $sRest = @{ + Uri = "https:/",$Script:CisServer.Server,'rest',$Request -join '/' + Method = $Method +# Body = &{if($Body){$Body}} + Body = &{if($Body){$Body | ConvertTo-Json -Depth 32}} + ContentType = 'application/json' + Headers = &{ + if($Script:CisServer.ContainsKey('vmware-api-session-id')){ + @{ + 'vmware-api-session-id' = "$($Script:CisServer.'vmware-api-session-id')" + } + } + else{ + @{ + Authorization = "$($Script:CisServer.AuthHeader)" + } + } + } + } + Try + { +# $result = Invoke-WebRequest @sRest + $result = Invoke-RestMethod @sRest + } + Catch + { + + } + $result + } +} + +function Connect-rCisServer{ + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] + param ( + [Parameter(Mandatory, Position = 1)] + [String]$Server, + [Parameter(Mandatory = $True,ValueFromPipeline = $True, Position = 2, ParameterSetName = 'Credential')] + [System.Management.Automation.PSCredential]$Credential, + [Parameter(Mandatory = $True, Position = 2, ParameterSetName = 'PlainText')] + [String]$User, + [Parameter(Mandatory = $True, Position = 3, ParameterSetName = 'PlainText')] + [String]$Password, + [string]$Proxy, + [Parameter(DontShow)] + [switch]$Fiddler = $false + ) + + Process + { + if ($Proxy) + { + if ($PSDefaultParameterValues.ContainsKey('*:Proxy')) + { + $PSDefaultParameterValues['*:Proxy'] = $Proxy + } + else + { + $PSDefaultParameterValues.Add('*:Proxy', $Proxy) + } + if ($PSDefaultParameterValues.ContainsKey('*:ProxyUseDefaultCredentials')) + { + $PSDefaultParameterValues['*:ProxyUseDefaultCredentials'] = $True + } + else + { + $PSDefaultParameterValues.Add('*:ProxyUseDefaultCredentials', $True) + } + } + if ($PSCmdlet.ParameterSetName -eq 'PlainText') + { + $sPswd = ConvertTo-SecureString -String $Password -AsPlainText -Force + $CisCredential = New-Object System.Management.Automation.PSCredential -ArgumentList ($User, $sPswd) + } + if ($PSCmdlet.ParameterSetName -eq 'Credential') + { + $CisCredential = $Credential + } + if ($Fiddler) + { + if (Get-Process -Name fiddler -ErrorAction SilentlyContinue) + { + if ($PSDefaultParameterValues.ContainsKey('Invoke-RestMethod:Proxy')) + { + $PSDefaultParameterValues['Invoke-RestMethod:Proxy'] = 'http://127.0.0.1:8888' + } + else + { + $PSDefaultParameterValues.Add('Invoke-RestMethod:Proxy', 'http://127.0.0.1:8888') + } + } + } + $Script:CisServer = @{ + Server = $Server + AuthHeader = &{ + $User = $CisCredential.UserName + $Password = $CisCredential.GetNetworkCredential().password + + $Encoded = [System.Text.Encoding]::UTF8.GetBytes(($User, $Password -Join ':')) + $EncodedPassword = [System.Convert]::ToBase64String($Encoded) + "Basic $($EncodedPassword)" + } + } + $sRest = @{ + Method = 'Post' + Request = 'com/vmware/cis/session' + } + If($PSCmdlet.ShouldProcess("CisServer $($Server)")) + { + $result = Invoke-vCisRest @sRest + + $Script:CisServer.Add('vmware-api-session-id',$result.value) + $Script:CisServer.Remove('AuthHeader') + } + } +} + +function Disconnect-rCisServer{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High')] + param ( + [Parameter(Mandatory = $True, Position = 1)] + [String]$Server + ) + + Process + { + if($Server -ne $Script:CisServer.Server){ + Write-Warning "You are not connected to server $($Server)" + } + + $sRest = @{ + Method = 'Delete' + Request = 'com/vmware/cis/session' + } + If($PSCmdlet.ShouldProcess("CisServer $($Server)")) + { + $result = Invoke-vCisRest @sRest + $Script:CisServer.Remove('vmware-api-session-id') + } + } +} + +function Get-rCisTag{` + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low', DefaultParameterSetName='Name')] + param ( + [Parameter(Position = 1, ParameterSetName='Name')] + [String[]]$Name, + [Parameter(Position = 2, ParameterSetName='Name',ValueFromPipeline = $true)] + [PSObject[]]$Category, + [Parameter(Mandatory = $True, Position = 1, ParameterSetName='Id')] + [String[]]$Id + ) + + Process + { + if($PSCmdlet.ParameterSetName -eq 'Name'){ + if($Category){ + $tagIds = $Category | %{ + $categoryIds = &{if($_ -is [string]){ + (Get-rCisTagCategory -Name $_).Id + } + else{ + $_.Id + }} + $categoryIds | %{ + # Get all tags in categories + $sRest = @{ + Method = 'Post' + Request = "com/vmware/cis/tagging/tag/id:$([uri]::EscapeDataString($_))?~action=list-tags-for-category" + } + (Invoke-vCisRest @sRest).value + } + } + } + else{ + $sRest = @{ + Method = 'Get' + Request = 'com/vmware/cis/tagging/tag' + } + $tagIds = (Invoke-vCisRest @sRest).value + } + } + else{ + $tagIds = $Id + } + + # Get category details + $out = @() + $tagIds | where{($PSCmdlet.ParameterSetName -eq 'Id' -and $Id -contains $_) -or $PSCmdlet.ParameterSetName -eq 'Name'} | %{ + $sRest = @{ + Method = 'Get' + Request = "com/vmware/cis/tagging/tag/id:$([uri]::EscapeDataString($_))" + } + $result = Invoke-vCisRest @sRest + + if($PSCmdlet.ParameterSetName -eq 'Id' -or ($PSCmdlet.ParameterSetName -eq 'Name' -and ($Name -eq $null -or $Name -contains $result.value.name))){ + $out += New-Object PSObject -Property @{ + Description = $result.value.description + Id = $result.value.id + Name = $result.value.name + Category = (Get-rCisTagCategory -Id $result.value.category_id).Name + Uid = "$($global:defaultviserver.Id)Tag=$($result.value.id)/" + Client = $global:defaultviserver.Client + } + } + } + $out | Select-Object Category,Description,Id,Name,Uid,Client + } + +} + +function Get-rCisTagCategory{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low', DefaultParameterSetName='Name')] + param ( + [Parameter(Position = 1, ParameterSetName='Name')] + [String[]]$Name, + [Parameter(Mandatory = $True, Position = 1, ParameterSetName='Id')] + [String[]]$Id + ) + + Begin + { + $txtInfo = (Get-Culture).TextInfo + $entityTab = @{ + 'ClusterComputeResource' = 'Cluster' + 'DistributedVirtualSwitch' = 'DistributedSwitch' + 'VmwareDistributedVirtualSwitch' = 'DistributedSwitch' + 'HostSystem' = 'VMHost' + 'DistributedVirtualPortGroup' = 'DistributedPortGroup' + 'VirtualApp' = 'VApp' + 'StoragePod' = 'DatastoreCluster' + 'Network' = 'VirtualPortGroup' + } + } + + Process + { + if($PSCmdlet.ParameterSetName -eq 'Name'){ + # Get all categories + $sRest = @{ + Method = 'Get' + Request = 'com/vmware/cis/tagging/category' + } + $tagCategoryIds = (Invoke-vCisRest @sRest).value + } + else{ + $tagCategoryIds = $Id + } + + # Get category details + $out = @() + $tagCategoryids | where{($PSCmdlet.ParameterSetName -eq 'Id' -and $Id -contains $_) -or $PSCmdlet.ParameterSetName -eq 'Name'} | %{ + $sRest = @{ + Method = 'Get' + Request = "com/vmware/cis/tagging/category/id:$([uri]::EscapeDataString($_))" + } + $result = Invoke-vCisRest @sRest + if($PSCmdlet.ParameterSetName -eq 'Id' -or ($PSCmdlet.ParameterSetName -eq 'Name' -and ($Name -eq $null -or $Name -contains $result.value.name))){ + $out += New-Object PSObject -Property @{ + Description = $result.value.description + Cardinality = $txtInfo.ToTitleCase($result.value.cardinality.ToLower()) + EntityType = @(&{ + if($result.value.associable_types.Count -eq 0){'All'} + else{ + $result.value.associable_types | %{ + if($entityTab.ContainsKey($_)){ + $entityTab.Item($_) + } + else{$_} + } + }} | Sort-Object -Unique) + Id = $result.value.id + Name = $result.value.name + Uid = "$($global:defaultviserver.Id)TagCategory=$($result.value.id)/" + Client = $global:defaultviserver.Client + } + } + } + $out | Select-Object Description,Cardinality,EntityType,Id,Name,Uid,Client + } +} + +function Get-rCisTagAssignment{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Low')] + param ( + [parameter(Position = 1, ValueFromPipeline = $true)] + [PSObject[]]$Entity, + [parameter(Position = 2)] + [PSObject[]]$Tag, + [parameter(Position = 3)] + [PSObject[]]$Category + ) + + Begin + { + if($Category.Count -ne 0 -or $Tag.Count -ne 0){ + $tagIds = @((Get-rCisTag -Name $Tag -Category $Category).Id) + } + else{ + $tagIds = @((Get-rCisTag).Id) + } + $out = @() + } + + Process + { + foreach($ent in $Entity){ + if($ent -is [string]){ + $ent = Get-Inventory -Name $ent -ErrorAction SilentlyContinue + } + + $entMoRef = New-Object PSObject -Property @{ + type = $ent.ExtensionData.MoRef.Type + id = $ent.ExtensionData.MoRef.Value + } + $sRest = @{ + Method = 'Post' + Request = 'com/vmware/cis/tagging/tag-association?~action=list-attached-tags-on-objects' + Body = @{ + object_ids = @($entMoRef) + } + } + $tagObj = (Invoke-vCisRest @sRest).value + foreach($obj in @($tagObj)){ + foreach($tag in ($obj.tag_ids | where{$tagIds -contains $_})){ + $sMoRef = "$($obj.object_id.type)-$($obj.object_id.id)" + $out += New-Object PSObject -Property @{ + Entity = (Get-View -id $sMoRef -Property Name).Name + Tag = (Get-rCisTag -Id $tag).Name + Id = 'com.vmware.cis.tagging.TagAssociationModel' + Name = 'com.vmware.cis.tagging.TagAssociationModel' + Uid = "$($global:defaultviserver.Id)VirtualMachine=$($sMoRef)/TagAssignment=/Tag=$($tag.tag_id)/" + Client = $global:defaultviserver.Client + } + } + } + } + } + + End + { + if($out.Count -eq 0) + { + $sRest = @{ + Method = 'Post' + Request = 'com/vmware/cis/tagging/tag-association?~action=list-attached-objects-on-tags' + Body = @{ + tag_ids = $tagIds + } + } + $tagObj = (Invoke-vCisRest @sRest).value + $out = foreach($tag in @(($tagObj | where{$tagIds -contains $_.tag_id}))){ + foreach($obj in $tag.object_ids){ + $sMoRef = "$($obj.type)-$($obj.id)" + New-Object PSObject -Property @{ + Entity = (Get-View -id $sMoRef -Property Name).Name + Tag = (Get-rCisTag -Id $tag.tag_id).Name + Id = 'com.vmware.cis.tagging.TagAssociationModel' + Name = 'com.vmware.cis.tagging.TagAssociationModel' + Uid = "$($global:defaultviserver.Id)VirtualMachine=$($sMoRef)/TagAssignment=/Tag=$($tag.tag_id)/" + Client = $global:defaultviserver.Client + } + } + } + } + + $out | Select-Object Uid,Tag,Entity,Id,Name,Client + } +} + +function New-rCisTag{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High')] + param ( + [Parameter(Mandatory=$true, Position = 1)] + [String[]]$Name, + [Parameter(Mandatory=$true, Position = 2,ValueFromPipeline = $true)] + [PSObject]$Category, + [Parameter(Position = 3)] + [string]$Description + ) + + Process + { + $out = @() + if($Category -is [String]){ + $Category = Get-rCisTagCategory -Name $Category + } + $Name | %{ + $sRest = @{ + Method = 'Post' + Request = 'com/vmware/cis/tagging/tag' + Body = @{ + create_spec = @{ + category_id = $Category.Id + name = $_ + description = $Description + } + } + } + $tagId = (Invoke-vCisRest @sRest).value + $out += New-Object PSObject -Property @{ + Category = $Category.Name + Description = $Description + Id = $tagId + Name = $_ + Uid = "$($global:defaultviserver.Id)Tag=$($tagId)/" + Client = $global:defaultviserver.Client + } + } + $out | Select-Object Category,Description,Id,Name,Uid,Client + } +} + +function New-rCisTagCategory{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High')] + param ( + [Parameter(Mandatory=$true, Position = 1)] + [String[]]$Name, + [Parameter(Position = 2)] + [ValidateSet('Single','Multiple')] + [string]$Cardinality = 'Single', + [Parameter(Position = 3)] + [string]$Description, + [Parameter(Position = 4)] + [string[]]$EntityType + ) + + Process + { + $out = @() + $Name | %{ + $sRest = @{ + Method = 'Post' + Request = 'com/vmware/cis/tagging/category' + Body = @{ + create_spec = @{ + cardinality = $Cardinality.ToUpper() + associable_types = @($EntityType) + name = $_ + description = $Description + } + } + } + $categoryId = (Invoke-vCisRest @sRest).value + $out += New-Object PSObject -Property @{ + Description = $Description + Cardinality = $Cardinality + EntityType = @($EntityType) + Id = $categoryId + Name = $_ + Uid = "$($global:defaultviserver.Id)TagCategory=$($categoryId)/" + Client = $global:defaultviserver.Client + } + } + $out | Select-Object Description,Cardinality,EntityType,Id,Name,Uid,Client + } +} + +function New-rCisTagAssignment{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High')] + param ( + [Parameter(Mandatory=$true, Position = 1)] + [String[]]$Tag, + [Parameter(Mandatory=$true,ValueFromPipeline = $true, Position = 2)] + [PSObject[]]$Entity + ) + + Process + { + $tagIds = @((Get-rCisTag -Name $Tag).Id) + $Entity = foreach($ent in $Entity){ + if($ent -is [string]){ + $ent = Get-Inventory -Name $ent -ErrorAction SilentlyContinue + } + $entMoRef = New-Object PSObject -Property @{ + type = $ent.ExtensionData.MoRef.Type + id = $ent.ExtensionData.MoRef.Value + } + foreach($tagId in $tagIds){ + $sRest = @{ + Method = 'Post' + Request = "com/vmware/cis/tagging/tag-association/id:$($tagId)?~action=attach" + Body = @{ + object_id = $entMoRef + } + } + Invoke-vCisRest @sRest + } + } + } + +# foreach($ent in +# if($Tag.Count -eq 1) +# { +# $tagId = (Get-rCisTag -Name $Tag).Id +# } +# elseif($Tag.Count -gt 1) +# { +# $tagIds = (Get-rCisTag -Name $Tag).Id +# } +# $Entity = foreach($ent in $Entity){ +# if($ent -is [string]){ +# Get-Inventory -Name $ent -ErrorAction SilentlyContinue +# } +# else{$ent} +# } +# +# if($Entity.Count -eq 1) +# { +# $entMoRef = New-Object PSObject -Property @{ +# type = $Entity[0].ExtensionData.MoRef.Type +# id = $Entity[0].ExtensionData.MoRef.Value +# } +# if($tag.Count -eq 1){ +# $sRest = @{ +# Method = 'Post' +# Request = "com/vmware/cis/tagging/tag-association/id:$($tagId)?~action=attach" +# Body = @{ +# object_id = $entMoRef +# } +# } +# Invoke-vCisRest @sRest +# } +# elseif($Tag.Count -gt 1){ +# $sRest = @{ +# Method = 'Post' +# Request = 'com/vmware/cis/tagging/tagassociation?~action=attach-multiple-tags-to-object' +# Body = @{ +# object_id = $entMoRef +# tag_ids = @($tagIds) +# } +# } +# Invoke-vCisRest @sRest +# } +# } +# elseif($Entity.Count -gt 1) +# { +# $entMorefs = $Entity | %{ +# New-Object PSObject -Property @{ +# type = $_.ExtensionData.MoRef.Type +# id = $_.ExtensionData.MoRef.Value +# } +# } +# if($tag.Count -eq 1){ +# $sRest = @{ +# Method = 'Post' +# Request = 'com/vmware/cis/tagging/tagassociation/id:$($tagId)?~action=attach-tag-to-multiple-objects' +# Body = @{ +# objects_ids = @($entMoRefs) +# tag_id = $tagId +# } +# } +# Invoke-vCisRest @sRest +# } +# elseif($Tag.Count -gt 1){ +# $tagIds | %{ +# $sRest = @{ +# Method = 'Post' +# Request = 'com/vmware/cis/tagging/tagassociation/id:$($tagId)?~action=attach-tag-to-multiple-objects' +# Body = @{ +# objects_ids = @($entMoRefs) +# tag_id = $_ +# } +# } +# Invoke-vCisRest @sRest +# } +# } +# } +# } +} + +function Remove-rCisTag{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High', DefaultParameterSetName='Name')] + param ( + [Parameter(Mandatory=$true, Position = 1, ValueFromPipeline = $true,ParameterSetName='Name')] + [PSObject[]]$Tag, + [Parameter(Mandatory=$true, Position = 1, ValueFromPipelineByPropertyName = $true,ParameterSetName='Id')] + [String[]]$Id + ) + + Process + { + if($PSCmdlet.ParameterSetName -eq 'Name'){ + foreach($tagObj in $Tag){ + if($tagObj -is [string]){ + $tagObj = Get-rCisTag -Name $tagObj + } + $sRest = @{ + Method = 'Delete' + Request = "com/vmware/cis/tagging/tag/id:$($tagObj.Id)" + } + Invoke-vCisRest @sRest + } + } + else{ + foreach($tagId in $Id){ + $sRest = @{ + Method = 'Delete' + Request = "com/vmware/cis/tagging/tag/id:$($tagId)" + } + Invoke-vCisRest @sRest + } + } + } +} + +function Remove-rCisTagCategory{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High', DefaultParameterSetName='Name')] + param ( + [Parameter(Mandatory=$true,Position = 1, ValueFromPipeline = $true,ParameterSetName='Name')] + [PSObject[]]$Category, + [Parameter(Mandatory=$true,Position = 1, ValueFromPipelineByPropertyName = $true,ParameterSetName='Id')] + [String[]]$Id + ) + + Process + { + if($PSCmdlet.ParameterSetName -eq 'Name'){ + foreach($catObj in $Category){ + if($catObj -is [string]){ + $catObj = Get-rCisTagCategory -Name $catObj + } + $sRest = @{ + Method = 'Delete' + Request = "com/vmware/cis/tagging/category/id:$($catObj.Id)" + } + Invoke-vCisRest @sRest + } + } + else{ + foreach($catId in $Id){ + $sRest = @{ + Method = 'Delete' + Request = "com/vmware/cis/tagging/category/id:$($catId)" + } + Invoke-vCisRest @sRest + } + } + } +} + +function Remove-rCisTagAssignment{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High',DefaultParameterSetName='Assignment')] + param ( + [Parameter(Mandatory=$true, Position = 1, ValueFromPipeline = $true,ParameterSetName='Assignment')] + [PSObject[]]$TagAssignment, + [Parameter(Mandatory=$true,Position = 1, ValueFromPipeline = $true,ParameterSetName='Name')] + [string[]]$Tag, + [Parameter(Position = 2, ParameterSetName='Name')] + [string[]]$Category, + [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName = $true,ParameterSetName='Id')] + [string[]]$TagId, + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [PSObject[]]$Entity + ) + + Process + { + + switch ($PSCmdlet.ParameterSetName){ + 'Name' { + $TagAssignment = Get-rCisTagAssignment -Entity $Entity -Tag $Tag -Category $Category + } + 'Id' { + $tags = Get-rCisTag -Id $TagId + $TagAssignment = Get-rCisTagAssignment -Tag $tags.Name -Entity $Entity + } + } + if($TagAssignment){ + $entMoRefs = @(Get-Inventory -Name $TagAssignment.Entity -ErrorAction SilentlyContinue | %{ + New-Object PSObject -Property @{ + type = $_.ExtensionData.MoRef.Type + id = $_.ExtensionData.MoRef.Value + } + }) + $tagIds = @((Get-rCisTag -Name $TagAssignment.Tag).Id) + } + + foreach($entMoRef in $entMoRefs){ + foreach($tId in $tagIds){ + $sRest = @{ + Method = 'Post' + Request = "com/vmware/cis/tagging/tag-association/id:$($tId)?~action=detach" + Body = @{ + object_id = $entMoRef + } + } + Invoke-vCisRest @sRest + } + } + } +} + +function Set-rCisTag{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High')] + param ( + [Parameter(Mandatory=$true, Position = 1, ValueFromPipeline = $true)] + [PSObject[]]$Tag, + [Parameter(Position = 2)] + [string]$Name, + [Parameter(Position = 3)] + [string]$Description + ) + + Process + { + foreach($tagObj in $Tag){ + if($tagObj -is [string]){ + $tagObj = Get-rCisTag -Name $tagObj + } + $sRest = @{ + Method = 'Patch' + Request = "com/vmware/cis/tagging/tag/id:$($tagObj.Id)" + Body = @{ + update_spec = @{ + name = $Name + description = $Description + } + } + } + Invoke-vCisRest @sRest + } + } +} + +function Set-rCisTagCategory{ + [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'High')] + param ( + [Parameter(Mandatory=$true, Position = 1, ValueFromPipeline = $true)] + [PSObject[]]$Category, + [Parameter(Position = 2)] + [string]$Name, + [Parameter(Position = 3)] + [ValidateSet('Single','Multiple')] + [string]$Cardinality, # Only SINGLE to MULTIPLE +# [string[]]$AddEntityType, # Does not work + [string]$Description + ) + + Process + { + foreach($catObj in $Category){ + if($catObj -is [string]){ + $catObj = Get-rCisTagCategory -Name $catObj + } + $sRest = @{ + Method = 'Patch' + Request = "com/vmware/cis/tagging/category/id:$($catObj.Id)" + Body = @{ + update_spec = @{ + } + } + } + if($Name){ + $sRest.Body.update_spec.Add('name',$Name) + } + if($Description){ + $sRest.Body.update_spec.Add('description',$Description) + } + if($Cardinality -and $catObj.Cardinality -eq 'SINGLE'){ + $sRest.Body.update_spec.Add('cardinality',$Cardinality.ToUpper()) + } + if($Name -or $Description -or $Cardinality){ + Invoke-vCisRest @sRest + } + } + } +}