New-QlikRule.ps1
function New-QlikRule { <# .SYNOPSIS This function ... .DESCRIPTION A bit more description .PARAMETER FromPipeline Shows how to process input from the pipeline, remaining parameters or by named parameter. .EXAMPLE New-QlikRule 'abc' Description of the example. #> <# Enable -Confirm and -WhatIf. #> [CmdletBinding(SupportsShouldProcess = $true)] param( [parameter(ValueFromPipeline=$true)] [PSObject]$object, [string]$name, [ValidateSet("License","Security","Sync")] [string]$category, [string]$rule, [alias("filter")] [string]$resourceFilter, [ValidateSet("hub","qmc","both")] [alias("context")] [string]$rulecontext = "both", [int]$actions, [string]$comment, [switch]$disabled ) begin { } process{ If( $object ) { $json = $object | ConvertTo-Json -Compress -Depth 10 } else { # category is case-sensitive so convert to Title Case $category = (Get-Culture).TextInfo.ToTitleCase($category.ToLower()) switch ($rulecontext) { both { $context = 0 } hub { $context = 1 } qmc { $context = 2 } } $json = (@{ category = $category; type = "Custom"; rule = $rule; name = $name; resourceFilter = $resourceFilter; actions = $actions; comment = $comment; disabled = $disabled.IsPresent; ruleContext = $context; tags = @(); schemaPath = "SystemRule" } | ConvertTo-Json -Compress) } return Invoke-QlikPost "/qrs/systemrule" $json } end { } } if ($loadingModule) { Export-ModuleMember -Function 'New-QlikRule' } |