Capa.PowerShell.Module.SDK.Inventory.psm1
|
<# .SYNOPSIS A function to convert Capa data types. .DESCRIPTION A function to convert Capa data types to a more readable format. .PARAMETER Datatype The data type to convert. .EXAMPLE PS C:\> Convert-CapaDataType -Datatype 1 .NOTES A custom function to convert Capa data types to a more readable format. #> function Convert-CapaDataType { [CmdletBinding()] [OutputType([string])] param ( [Parameter(Mandatory = $true)] $Datatype ) switch ($DataType) { 1 { $Datatype = 'String' } 2 { $Datatype = 'Time' } 3 { $Datatype = 'Integer' } 'I' { $Datatype = 'Integer' } 'T' { $Datatype = 'Time' } 'S' { $Datatype = 'String' } 'N' { $Datatype = 'Text' } Default { $Datatype = $Datatype } } return $Datatype } <# .SYNOPSIS Get custom inventory categories and entries. .DESCRIPTION Get custom inventory categories and entries. .PARAMETER CapaSDK The CapaSDK object. .EXAMPLE PS C:\> Get-CapaCustomInventoryCategoriesAndEntries -CapaSDK $CapaSDK .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246428/GetCustomInventoryCategoriesAndEntries #> function Get-CapaCustomInventoryCategoriesAndEntries { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK ) $oaUnits = @() $aUnits = $CapaSDK.GetCustomInventoryCategoriesAndEntries() foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $Datatype = Convert-CapaDataType -Datatype $aItem[2] $oaUnits += [pscustomobject]@{ Category = $aItem[0]; Entry = $aItem[1]; Datatype = $Datatype } } return $oaUnits } <# .SYNOPSIS Get the custom inventory for a unit. .DESCRIPTION Get the custom inventory for a unit, with the option to get the inventory by name and type or by UUID. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName The name of the unit. .PARAMETER UnitType The type of the unit. .PARAMETER Uuid The UUID of the unit. .EXAMPLE PS C:\> Get-CapaCustomInventoryForUnit -Uuid 'E3FBEC1E-32AC-4E51-AB9F-A644CD9F0A6B' .EXAMPLE PS C:\> Get-CapaCustomInventoryForUnit -UnitName 'CAPA-TEST-01' -UnitType 'Computer' .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246358/Get+custom+inventory+for+unit #> function Get-CapaCustomInventoryForUnit { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateSet('Computer', 'User')] [string]$UnitType, [Parameter(ParameterSetName = 'Uuid', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Uuid ) $oaUnits = @() if ($PSCmdlet.ParameterSetName -eq 'NameType') { $aUnits = $CapaSDK.GetCustomInventoryForUnit($UnitName, $UnitType) } else { $aUnits = $CapaSDK.GetCustomInventoryForUnitUUID($Uuid) } foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $DataType = Convert-CapaDataType -Datatype $aItem[3] $oaUnits += [pscustomobject]@{ Category = $aItem[0]; Entry = $aItem[1]; Value = $aItem[2]; Datatype = $DataType; GUID = $aItem[4]; ID = $aItem[5] } } return $oaUnits } <# .SYNOPSIS Get the hardware inventory for a unit. .DESCRIPTION Get the hardware inventory for a unit. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName Can be the name of a unit or the UUID. .PARAMETER UnitType The type of the unit, can be Computer or User. .EXAMPLE PS C:\> Get-CapaHardwareInventoryForUnit -CapaSDK $CapaSDK -UnitName 'Klient' -UnitType Computer .EXAMPLE PS C:\> Get-CapaHardwareInventoryForUnit -CapaSDK $CapaSDK -UnitName 'E3FBEC1E-32AC-4E51-AB9F-A644CD9F0A6B' -UnitType Computer .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246368/Get+hardware+inventory+for+unit #> function Get-CapaHardwareInventoryForUnit { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(Mandatory = $true)] [ValidateSet('Computer', 'User')] [string]$UnitType ) $UnitTypeId = if ($UnitType -eq 'Computer') { '1' } else { '2' } $oaUnits = @() $aUnits = $CapaSDK.GetHardwareInventoryForUnit($UnitName, $UnitTypeId) foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $DataType = Convert-CapaDataType -Datatype $aItem[3] $oaUnits += [pscustomobject]@{ Category = $aItem[0]; Entry = $aItem[1]; Value = $aItem[2]; Datatype = $DataType; GUID = $aItem[4]; ID = $aItem[5] } } return $oaUnits } <# .SYNOPSIS Get logon history for a unit. .DESCRIPTION Get logon history for a unit. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName Can be the name of a unit or the UUID. .PARAMETER UnitType The type of the unit, can be Computer or User. .EXAMPLE PS C:\> Get-CapaLogonHistoryForUnit -CapaSDK $CapaSDK -UnitName 'Klient' -UnitType Computer .EXAMPLE PS C:\> Get-CapaLogonHistoryForUnit -CapaSDK $CapaSDK -UnitName 'E3FBEC1E-32AC-4E51-AB9F-A644CD9F0A6B' -UnitType Computer .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246378/Get+logon+history+for+unit #> function Get-CapaLogonHistoryForUnit { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(Mandatory = $true)] [ValidateSet('Computer', 'User')] [string]$UnitType ) $UnitTypeId = if ($UnitType -eq 'Computer') { '1' } else { '2' } $oaUnits = @() $aUnits = $CapaSDK.GetLogonHistoryForUnit($UnitName, $UnitTypeId) foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $DataType = Convert-CapaDataType -Datatype $aItem[3] $oaUnits += [pscustomobject]@{ Category = $aItem[0]; Entry = $aItem[1]; Value = $aItem[2]; Datatype = $DataType; GUID = $aItem[4]; ID = $aItem[5] } } return $oaUnits } <# .SYNOPSIS Get metering groups. .DESCRIPTION Gets a list of metering groups. .PARAMETER CapaSDK The CapaSDK object. .EXAMPLE PS C:\> Get-CapaMeteringGroups -CapaSDK $CapaSDK .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246388/Get+metering+groups #> function Get-CapaMeteringGroups { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK ) $oaUnits = @() $aUnits = $CapaSDK.GetMeteringGroups() foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $oaUnits += [pscustomobject]@{ Name = $aItem[0]; Version = $aItem[1]; Vendor = $aItem[2]; AppCode = $aItem[3]; Description = $aItem[4]; MeteringModule = $aItem[5]; GUID = $aItem[6]; ID = $aItem[7] } } return $oaUnits } <# .SYNOPSIS Get software inventory for a unit. .DESCRIPTION Get software inventory for a unit. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName The name of the unit. .PARAMETER UnitType The type of the unit, can be Computer or User. .PARAMETER Uuid The UUID of the unit. .EXAMPLE PS C:\> Get-CapaSoftwareInventoryForUnit -CapaSDK $CapaSDK -UnitName 'Klient' -UnitType Computer .EXAMPLE PS C:\> Get-CapaSoftwareInventoryForUnit -CapaSDK $CapaSDK -UnitName 'E3FBEC1E-32AC-4E51-AB9F-A644CD9F0A6B' -UnitType Computer .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246398/Get+software+inventory+for+unit #> function Get-CapaSoftwareInventoryForUnit { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateSet('Computer', 'User')] [string]$UnitType, [Parameter(ParameterSetName = 'Uuid', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Uuid ) $UnitTypeId = if ($UnitType -eq 'Computer') { '1' } elseif ($UnitType -eq 'User') { '2' } else { $UnitType } $oaUnits = @() if ($PSCmdlet.ParameterSetName -eq 'NameType') { $aUnits = $CapaSDK.GetSoftwareInventoryForUnit($UnitName, $UnitTypeId) } else { $aUnits = $CapaSDK.GetSoftwareInventoryForUnit($Uuid, $UnitTypeId) } foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $oaUnits += [pscustomobject]@{ SoftwareName = $aItem[0]; SoftwareVersion = $aItem[1]; InstallDate = $aItem[2]; SoftwareMeteringModule = $aItem[3]; SoftwareAppCode = $aItem[4]; SoftwareDescription = $aItem[5]; SoftwareID = $aItem[6]; SoftwareVendor = $aItem[7] } } return $oaUnits } <# .SYNOPSIS Get update inventory for a unit. .DESCRIPTION Get a list of update inventory for a unit. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName The name of the unit. .PARAMETER UnitType The type of the unit, can be Computer or User. .EXAMPLE PS C:\> Get-CapaUpdateInventoryForUnit -CapaSDK $CapaSDK -UnitName 'Klient' -UnitType Computer .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246408/Get+update+inventory+for+unit #> function Get-CapaUpdateInventoryForUnit { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(Mandatory = $true)] [ValidateSet('Computer', 'User')] [string]$UnitType ) $oaUnits = @() $aUnits = $CapaSDK.GetUpdateInventoryForUnit($UnitName, $UnitType) foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $oaUnits += [pscustomobject]@{ Qfename = $aItem[0]; InstallDate = $aItem[1]; UpdateID = $aItem[2]; UpdateName = $aItem[3]; Revision = $aItem[4]; InstallCount = $aItem[5]; Status = $aItem[6] } } return $oaUnits } <# .SYNOPSIS Get software inventory for a user. .DESCRIPTION Get software inventory for a user. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UserName The username of the user. .EXAMPLE PS C:\> Get-CapaSoftwareInventoryForUser -CapaSDK $CapaSDK -UserName 'Klient' .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246418/Get+User+Inventory #> function Get-CapaUserInventory { [CmdletBinding()] [OutputType([pscustomobject[]])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UserName ) $oaUnits = @() $aUnits = $CapaSDK.GetUserInventory($UserName) foreach ($sItem in $aUnits) { $aItem = $sItem.Split(';') $oaUnits += [pscustomobject]@{ Category = $aItem[0]; Entry = $aItem[1]; Value = $aItem[2]; Datatype = $aItem[3]; GUID = $aItem[4]; ID = $aItem[5] } } return $oaUnits } <# .SYNOPSIS Set custom inventory for a unit. .DESCRIPTION Set custom inventory for a unit, either by name and type or by UUID. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName The name of the unit. .PARAMETER UnitType The type of the unit, can be Computer or User. .PARAMETER Uuid The UUID of the unit. .PARAMETER Section The inventory section. .PARAMETER Name The name of the value. .PARAMETER Value The value. .PARAMETER DataType The data type of the value, can be String, Integer, Text or Time. .EXAMPLE PS C:\> Set-CapaCustomInventory -CapaSDK $CapaSDK -UnitName 'Klient' -UnitType Computer -Section 'Antivirus' -Name 'Version' -Value '4' -DataType Integer .NOTES For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246438/Set+custom+inventory #> function Set-CapaCustomInventory { [CmdletBinding(DefaultParameterSetName = 'NameType', SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] [OutputType([object])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateSet('1', '2', 'Computer', 'User')] [string]$UnitType, [Parameter(ParameterSetName = 'Uuid', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Uuid, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Section, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Name, [Parameter(Mandatory = $true)] [string]$Value, [Parameter(Mandatory = $true)] [ValidateSet('Integer', 'Time', 'String', 'Text', 'I', 'T', 'S', 'N')] [string]$DataType ) switch ($UnitType) { 'Computer' { $UnitType = '1' } 'User' { $UnitType = '2' } default { } } switch ($DataType) { 'Integer' { $DataType = 'I' } 'Time' { $DataType = 'T' } 'String' { $DataType = 'S' } 'Text' { $DataType = 'N' } default { } } $Target = if ($PSCmdlet.ParameterSetName -eq 'NameType') { $UnitName } else { $Uuid } if ($PSCmdlet.ShouldProcess($Target, "Set custom inventory '$Section\$Name'")) { if ($PSCmdlet.ParameterSetName -eq 'NameType') { $value = $CapaSDK.SetCustomInventory($UnitName, $UnitType, $Section, $Name, $Value, $DataType) } else { $value = $CapaSDK.SetCustomInventoryUUID($Uuid, $Section, $Name, $Value, $DataType) } return $value } } <# .SYNOPSIS Set hardware inventory for a unit. .DESCRIPTION Set hardware inventory for a unit, either by name and type or by UUID. .PARAMETER CapaSDK The CapaSDK object. .PARAMETER UnitName The name of the unit. .PARAMETER UnitType The type of the unit, can be Computer or User. .PARAMETER Uuid The UUID of the unit. .PARAMETER Section The inventory section. .PARAMETER Name The name of the value. .PARAMETER Value The value. .PARAMETER DataType The data type of the value, can be String, Integer, Text or Time. .EXAMPLE PS C:\> Set-CapaSetCustomInventory .NOTES When inventory from the unit is collected by the CapaInstaller Backend, these settings will be deleted if not present in the inventory data collected. For more information, see https://capasystems.atlassian.net/wiki/spaces/CI64DOC/pages/19306246446/Set+hardware+inventory #> function Set-CapaHardwareInventory { [CmdletBinding(DefaultParameterSetName = 'NameType', SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] [OutputType([object])] param ( [Parameter(Mandatory = $true)] [ValidateNotNull()] $CapaSDK, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$UnitName, [Parameter(ParameterSetName = 'NameType', Mandatory = $true)] [ValidateSet('1', '2', 'Computer', 'User')] [string]$UnitType, [Parameter(ParameterSetName = 'Uuid', Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Uuid, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Section, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string]$Name, [Parameter(Mandatory = $true)] [string]$Value, [Parameter(Mandatory = $true)] [ValidateSet('Integer', 'Time', 'String', 'Text', 'I', 'T', 'S', 'N')] [string]$DataType ) switch ($UnitType) { 'Computer' { $UnitType = '1' } 'User' { $UnitType = '2' } default { } } switch ($DataType) { 'Integer' { $DataType = 'I' } 'Time' { $DataType = 'T' } 'String' { $DataType = 'S' } 'Text' { $DataType = 'N' } default { } } $Target = if ($PSCmdlet.ParameterSetName -eq 'NameType') { $UnitName } else { $Uuid } if ($PSCmdlet.ShouldProcess($Target, "Set hardware inventory '$Section\$Name'")) { if ($PSCmdlet.ParameterSetName -eq 'NameType') { $value = $CapaSDK.SetHardwareInventory($UnitName, $UnitType, $Section, $Name, $Value, $DataType) } else { $value = $CapaSDK.SetHardwareInventoryUUID($Uuid, $Section, $Name, $Value, $DataType) } return $value } } |