Function Get-CoreQueryArrayList { <# .SYNOPSIS Returns array of search critera used by Invoke-CoreWhereWrapper .DESCRIPTION Internal function Array of search critera that will make up the load_arg value part of the JSON query for Where querys The JSON format for Where search criteria is an array of arrays that contain 3 entries. The search attribute, the operator and the search criteria We build this arry in the Find-Core functions, like Get-CoreTicket and Get-CoreComputer This built as a hashtable in these functions then passed to this function by Invoke-CoreWhereWrapper to convert it to an array, so the invoke-corequery function will have properly .PARAMETER Values Mandatory Hashtable of arrays of search criteria, generated by Find-Core functions, like Get-CoreTicket and Get-CoreComputer .EXAMPLE Name Value ---- ----- Accounts {account, in, 1103359} .OUTPUTS ArrayList of search items .NOTES Written by Martin Howlett / Mark Wichall #> Param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [Hashtable]$Values ) Write-Verbose "Start of $($MyInvocation.MyCommand)" #our array of search critera that will make up the load_arg value part of the JSON query [System.Collections.ArrayList]$ValueArray = @() $EntryCount = 0 Write-Verbose "Hashtable contents for `$Values in Get-CoreQueryArrayList:" foreach ($h in $Values.GetEnumerator()) { Write-Verbose "$($h.Name): $($h.Value)" } #iterate through the hash table, adding the values to the array foreach ($Entry in $Values.GetEnumerator()) { $ValueArray.Add($($Entry.Value)) | Out-Null $EntryCount ++ #only add the AND operator if we are not at the end of the hash table if($EntryCount -ne $Values.Keys.count) { $ValueArray.Add("&") | Out-Null } } Write-Verbose "End of $($MyInvocation.MyCommand)" return $ValueArray } Function Get-UniqueArray { <# .SYNOPSIS Makes an array unique and returns it as an ArrayList .DESCRIPTION Internal function Makes an array unique and returns it as an ArrayList .PARAMETER InputArray Mandatory The array of information to make unique .EXAMPLE $Computers = Get-UniqueArray -InputArray @(560559,560559,560557) $Computers will equal @(560559,560557) .OUTPUTS [System.Collections.ArrayList] .NOTES Written by Martin Howlett / Mark Wichall #> Param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [Array]$InputArray ) Write-Verbose "Start of $($MyInvocation.MyCommand)" #make sure unique $InputArray = $InputArray | Sort-Object -Unique -CaseSensitive Write-Verbose "End of $($MyInvocation.MyCommand)" #make sure we return an arraylist so our single entry arrays dont break later Return [System.Collections.ArrayList]$InputArray } Function Edit-StringPadding { <# .SYNOPSIS Pads a string with spaces to required length .DESCRIPTION Pads a string with spaces to required length .PARAMETER StringTotalLength Mandatory Integar of the total length you want the string .PARAMETER String Mandatory The string to pad .EXAMPLE Edit-StringPadding -StringTotalLength 50 -String "banana" Will pad the string banana with 44 spaces Like so: "banana " .OUTPUTS The padded string .NOTES Written by Martin Howlett #> Param ( [Parameter(mandatory=$true)] [Int]$StringTotalLength, [Parameter(mandatory=$true)] [string]$String ) #check our string is longer then the total lengeh, if it is cut it down if (($String | Measure-Object -Character).Characters -ge $StringTotalLength) { $String = $String.substring(0, $StringTotalLength) } else { #work out how much we need to pad the string and padd it with spaces $Pad = $StringTotalLength - ($String | Measure-Object -Character).Characters $arr = 0 do{ [string]$String = "$String " $arr++ } until ($arr -eq $Pad) } Return $String } Function Write-AttributesToHost { <# .SYNOPSIS Prints to screen the attribute groups in the Get-CoreAttribute functions .DESCRIPTION Parses a hashtable of all the attribute groups in a Get-CoreAttribute function and prints them to screen, displaying attribute group name, the PoshCore name, the Core api value and the Custom attribute syntax in case you want to return just that value Example output of default values for ticket (note, values subject to change) Attribute group name: Default ---------------------------------------------------------------------------------------------------------------------- | PoshCore name: | Core API value: | Custom attribute syntax: | ---------------------------------------------------------------------------------------------------------------------- | queue_id | queue.id | @{"queue_id"="queue.id"} | | number | number | @{"number"="number"} | | subject | subject | @{"subject"="subject"} | | submitter | submitter.name | @{"submitter"="submitter.name"} | | queue_name | queue.name | @{"queue_name"="queue.name"} | | assignee_name | assignee.name | @{"assignee_name"="assignee.name"} | | private | private | @{"private"="private"} | ---------------------------------------------------------------------------------------------------------------------- This function is only called from Get-CoreAttribute after generating a specially formatted hashtable Depends on function Edit-StringPadding .PARAMETER AttributeHashtable Mandatory A hashtable of all the hashtables of groups of attributes You can generate this at the bottom of a Get-CoreAttribute function using this code: $AttributeClass = "Computer" $AllGroups = @("Network","Drac","Bandwidth","Attached","Backup","Storage","Misc","Domain","Implementation","Is","Os","Password") $AttributeHashtable = @{} ForEach ($Group in $AllGroups) { $AttributeHashtable.Add($Group,$((Get-Variable -Name "$Group$AttributeClass`Attributes").Value)) } Write-AttributesToHost -AttributeHashtable $AttributeHashtable If it really important your $AllGroups variable matches the ValidateSet for the Attribute param on the Get-CoreAttribute function Also do not forget to change the $AttributeClass variable .EXAMPLE When called from Get-CoreComputerAttribute $AttributeClass = "Computer" $AllGroups = @("Network","Drac","Bandwidth","Attached","Backup","Storage","Misc","Domain","Implementation","Is","Os","Password") $AttributeHashtable = @{} ForEach ($Group in $AllGroups) { $AttributeHashtable.Add($Group,$((Get-Variable -Name "$Group$AttributeClass`Attributes").Value)) } Write-AttributesToHost -AttributeHashtable $AttributeHashtable It is important this is at the bottom of the function, so all the individual hash tables for the attributes are created .OUTPUTS Writes to screen in a nice table the attribute groups and their properties .NOTES Written by Martin Howlett #> [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [Hashtable]$AttributeHashtable ) #zero out our values $NamePadLength = $ValuePadLength = $CustomPadLength = 0 #loop through the hash of attribute groups then loop through each attribute value getting the longest one #this is so we can pad the table nicely foreach ($Group in $AttributeHashtable.Values.GetEnumerator()) { foreach ($Value in $Group.GetEnumerator()) { #find out pad string maximums if( $($Value.Name).Length -gt $NamePadLength) { $NamePadLength = $($Value.Name).Length } if( $($Value.Value).Length -gt $ValuePadLength) { $ValuePadLength = $($Value.Value).Length } #we add 5 to custom length to account for speechmarks and the = symbol $CustomLength = "@{$($Value.Name)$($Value.Value)}".Length +5 if($CustomLength -gt $CustomPadLength) { $CustomPadLength = $CustomLength } } } #we add 10 to account for the spaces and pipes $Totalwidth = ($NamePadLength + $ValuePadLength + $CustomPadLength + 10) #start writing to screen foreach ($Key in $AttributeHashtable.Keys.GetEnumerator()) { #group header and name write-host " " write-host " " write-host "Attribute group name: $Key" -ForegroundColor Yellow write-host "$("-" * $Totalwidth)" #title Write-Host "| $(Edit-StringPadding -StringTotalLength $NamePadLength -String "PoshCore name:") " -NoNewline Write-Host "| $(Edit-StringPadding -StringTotalLength $ValuePadLength -String "Core API value:") " -NoNewline Write-Host "| $(Edit-StringPadding -StringTotalLength $CustomPadLength -String "Custom attribute syntax:") |" #seperator write-host "$("-" * $Totalwidth)" #indivual keys foreach ($Value in $AttributeHashtable["$Key"].GetEnumerator()) { $CustomString = "@{`"$($Value.Name)`"=`"$($Value.Value)`"}" Write-Host "| $(Edit-StringPadding -StringTotalLength $NamePadLength -String "$($Value.Name)") " -NoNewline Write-Host "| $(Edit-StringPadding -StringTotalLength $ValuePadLength -String $($Value.Value)) " -NoNewline Write-Host "| $(Edit-StringPadding -StringTotalLength $CustomPadLength -String $CustomString) |" } #footer write-host "$("-" * $Totalwidth)" } }