2019-09-13 05:44:37 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Exports command as JSON for icinga director
|
|
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Get-IcingaCheckCommandConfig returns a JSON-file of one or all 'Invoke-IcingaCheck'-Commands, which can be imported via Icinga-Director
|
|
|
|
|
When no single command is specified all commands will be exported, and vice versa.
|
|
|
|
|
|
|
|
|
|
More Information on https://github.com/LordHepipud/icinga-module-windows
|
|
|
|
|
|
|
|
|
|
.FUNCTIONALITY
|
|
|
|
|
This module is intended to be used to export one or all PowerShell-Modules with the namespace 'Invoke-IcingaCheck'.
|
|
|
|
|
The JSON-Export, which will be egenerated through this module is structured like an Icinga-Director-JSON-Export, so it can be imported via the Icinga-Director the same way.
|
|
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS>Get-IcingaCheckCommandConfig
|
|
|
|
|
Check Command JSON for the following commands:
|
|
|
|
|
- 'Invoke-IcingaCheckBiosSerial'
|
|
|
|
|
- 'Invoke-IcingaCheckCPU'
|
|
|
|
|
- 'Invoke-IcingaCheckProcessCount'
|
|
|
|
|
- 'Invoke-IcingaCheckService'
|
|
|
|
|
- 'Invoke-IcingaCheckUpdates'
|
|
|
|
|
- 'Invoke-IcingaCheckUptime'
|
|
|
|
|
- 'Invoke-IcingaCheckUsedPartitionSpace'
|
|
|
|
|
- 'Invoke-IcingaCheckUsers'
|
|
|
|
|
############################################################
|
|
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
Get-IcingaCheckCommandConfig -OutFile 'C:\Users\icinga\config-exports'
|
|
|
|
|
The following commands have been exported:
|
|
|
|
|
- 'Invoke-IcingaCheckBiosSerial'
|
|
|
|
|
- 'Invoke-IcingaCheckCPU'
|
|
|
|
|
- 'Invoke-IcingaCheckProcessCount'
|
|
|
|
|
- 'Invoke-IcingaCheckService'
|
|
|
|
|
- 'Invoke-IcingaCheckUpdates'
|
|
|
|
|
- 'Invoke-IcingaCheckUptime'
|
|
|
|
|
- 'Invoke-IcingaCheckUsedPartitionSpace'
|
|
|
|
|
- 'Invoke-IcingaCheckUsers'
|
|
|
|
|
JSON export created in 'C:\Users\icinga\config-exports\PowerShell_CheckCommands_09-13-2019-10-55-1989.json'
|
|
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
Get-IcingaCheckCommandConfig Invoke-IcingaCheckBiosSerial, Invoke-IcingaCheckCPU -OutFile 'C:\Users\icinga\config-exports'
|
|
|
|
|
The following commands have been exported:
|
|
|
|
|
- 'Invoke-IcingaCheckBiosSerial'
|
|
|
|
|
- 'Invoke-IcingaCheckCPU'
|
|
|
|
|
JSON export created in 'C:\Users\icinga\config-exports\PowerShell_CheckCommands_09-13-2019-10-58-5342.json'
|
|
|
|
|
|
|
|
|
|
.PARAMETER CheckName
|
|
|
|
|
Used to specify an array of commands which should be exported.
|
|
|
|
|
Seperated with ','
|
|
|
|
|
|
2019-09-13 10:24:30 -04:00
|
|
|
.INPUTS
|
2019-09-13 05:44:37 -04:00
|
|
|
System.Array
|
|
|
|
|
|
2019-09-13 10:24:30 -04:00
|
|
|
.OUTPUTS
|
2019-09-13 05:44:37 -04:00
|
|
|
System.String
|
|
|
|
|
|
2019-09-13 10:24:30 -04:00
|
|
|
.LINK
|
2019-09-13 05:44:37 -04:00
|
|
|
https://github.com/LordHepipud/icinga-module-windows
|
|
|
|
|
|
2019-09-13 10:24:30 -04:00
|
|
|
.NOTES
|
2019-09-13 05:44:37 -04:00
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
function Get-IcingaCheckCommandConfig()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(ValueFromPipeline)]
|
|
|
|
|
[array]$CheckName,
|
|
|
|
|
[string]$OutFile
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Check whether all Checks will be exported or just the ones specified
|
|
|
|
|
if ([string]::IsNullOrEmpty($CheckName) -eq $true) {
|
|
|
|
|
$CheckName = (Get-Command Invoke-IcingaCheck*).Name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[int]$FieldID = 2; # Starts at '2', because '0' and '1' are reserved for 'Verbose' and 'NoPerfData'
|
|
|
|
|
[hashtable]$Basket = @{};
|
|
|
|
|
|
|
|
|
|
# Define basic hashtable structure by adding fields: "Datafield", "DataList", "Command"
|
|
|
|
|
$Basket.Add('Datafield', @{});
|
|
|
|
|
$Basket.Add('DataList', @{});
|
|
|
|
|
$Basket.Add('Command', @{});
|
|
|
|
|
|
|
|
|
|
# "Verbose" gets added to all Checks build and exported no matter what, so we add it from the start
|
|
|
|
|
if ($Basket.DataList.ContainsKey('PowerShell Verbose') -eq $FALSE) {
|
|
|
|
|
$Basket.DataList.Add(
|
|
|
|
|
'PowerShell Verbose', @{
|
|
|
|
|
'list_name' = 'PowerShell Verbose';
|
|
|
|
|
'owner' = $env:username;
|
|
|
|
|
'originalId' = '2';
|
|
|
|
|
'entries' = @(
|
|
|
|
|
@{
|
|
|
|
|
'entry_name' = '0';
|
2019-09-16 06:02:38 -04:00
|
|
|
'entry_value' = "Show Default";
|
2019-09-13 05:44:37 -04:00
|
|
|
'format' = 'string';
|
|
|
|
|
'allowed_roles' = $NULL;
|
|
|
|
|
},
|
|
|
|
|
@{
|
|
|
|
|
'entry_name' = '1';
|
2019-09-16 06:02:38 -04:00
|
|
|
'entry_value' = "Show Operator";
|
2019-09-13 05:44:37 -04:00
|
|
|
'format' = 'string';
|
|
|
|
|
'allowed_roles' = $NULL;
|
|
|
|
|
},
|
|
|
|
|
@{
|
|
|
|
|
'entry_name' = '2';
|
2019-09-16 06:02:38 -04:00
|
|
|
'entry_value' = "Show Problems";
|
2019-09-13 05:44:37 -04:00
|
|
|
'format' = 'string';
|
|
|
|
|
'allowed_roles' = $NULL;
|
|
|
|
|
},
|
|
|
|
|
@{
|
|
|
|
|
'entry_name' = '3';
|
2019-09-16 06:02:38 -04:00
|
|
|
'entry_value' = "Show All";
|
2019-09-13 05:44:37 -04:00
|
|
|
'format' = 'string';
|
|
|
|
|
'allowed_roles' = $NULL;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Loop through ${CheckName}, to get information on every command specified/all commands.
|
|
|
|
|
foreach ($check in $CheckName) {
|
|
|
|
|
|
|
|
|
|
# Get necessary syntax-information and more through cmdlet "Get-Help"
|
|
|
|
|
$Data = (Get-Help $check)
|
|
|
|
|
|
|
|
|
|
# Add command Structure
|
|
|
|
|
$Basket.Command.Add(
|
2019-09-16 09:33:57 -04:00
|
|
|
$Data.Name, @{
|
2019-09-13 05:44:37 -04:00
|
|
|
'arguments'= @{
|
|
|
|
|
# Gets set for every command as default
|
|
|
|
|
'-C' = @{
|
2019-09-16 09:33:57 -04:00
|
|
|
'value' = [string]::Format('Use-Icinga; {0}', $Data.Name);
|
2019-09-13 05:44:37 -04:00
|
|
|
'order' = '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'command' = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
|
|
|
|
|
'disabled' = $FALSE;
|
2019-09-16 09:33:57 -04:00
|
|
|
'fields' = @();
|
2019-09-13 05:44:37 -04:00
|
|
|
'imports' = @();
|
|
|
|
|
'is_string' = $NULL;
|
2019-09-16 06:06:05 -04:00
|
|
|
'methods_execute' = 'PluginCheck';
|
2019-09-16 09:33:57 -04:00
|
|
|
'object_name' = $Data.Name;
|
2019-09-13 05:44:37 -04:00
|
|
|
'object_type' = 'object';
|
|
|
|
|
'timeout' = '180';
|
|
|
|
|
'vars' = @{};
|
|
|
|
|
'zone' = $NULL;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Loop through parameters of a given command
|
2019-09-16 09:33:57 -04:00
|
|
|
foreach ($parameter in $Data.parameters.parameter) {
|
2019-09-13 05:44:37 -04:00
|
|
|
|
|
|
|
|
# Filter for Parameter 'core', because its set by default
|
|
|
|
|
if ($parameter.name -ne 'core') {
|
|
|
|
|
|
|
|
|
|
# IsNumeric-Check on position to determine the order-value
|
|
|
|
|
If (Test-Numeric($parameter.position) -eq $TRUE) {
|
|
|
|
|
[string]$Order = [int]$parameter.position + 1;
|
|
|
|
|
} else {
|
|
|
|
|
[string]$Order = 99
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$IcingaCustomVariable = [string]::Format('$PowerShell_{0}_{1}$', $parameter.type.name, $parameter.Name);
|
|
|
|
|
|
|
|
|
|
# Add arguments to a given command
|
|
|
|
|
if ($parameter.type.name -eq 'switch') {
|
2019-09-16 09:33:57 -04:00
|
|
|
$Basket.Command[$Data.Name].arguments.Add(
|
2019-09-13 05:44:37 -04:00
|
|
|
[string]::Format('-{0}', $parameter.Name), @{
|
|
|
|
|
'set_if' = $IcingaCustomVariable;
|
|
|
|
|
'set_if_format' = 'string';
|
|
|
|
|
'order' = $Order;
|
|
|
|
|
}
|
|
|
|
|
);
|
2019-09-16 09:33:57 -04:00
|
|
|
|
|
|
|
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, $FALSE);
|
2019-09-13 05:44:37 -04:00
|
|
|
|
|
|
|
|
# Conditional whether type of parameter is array
|
|
|
|
|
} elseif ($parameter.type.name -eq 'array') {
|
2019-09-16 09:33:57 -04:00
|
|
|
$Basket.Command[$Data.Name].arguments.Add(
|
2019-09-13 05:44:37 -04:00
|
|
|
[string]::Format('-{0}', $parameter.Name), @{
|
2019-09-13 09:59:22 -04:00
|
|
|
'value' = @{
|
|
|
|
|
'type' = 'Function';
|
|
|
|
|
'body' = [string]::Format(
|
2019-09-13 10:01:46 -04:00
|
|
|
'var arr = macro("{0}");{1}if (len(arr) == 0) {2}{1}return "$null";{1}{3}{1}return arr.join(",");',
|
|
|
|
|
$IcingaCustomVariable,
|
|
|
|
|
"`r`n",
|
|
|
|
|
'{',
|
|
|
|
|
'}'
|
|
|
|
|
);
|
2019-09-13 09:59:22 -04:00
|
|
|
}
|
2019-09-13 05:44:37 -04:00
|
|
|
'order' = $Order;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2019-09-16 09:33:57 -04:00
|
|
|
# Default to Object
|
|
|
|
|
$Basket.Command[$Data.Name].arguments.Add(
|
2019-09-13 05:44:37 -04:00
|
|
|
[string]::Format('-{0}', $parameter.Name), @{
|
|
|
|
|
'value' = $IcingaCustomVariable;
|
|
|
|
|
'order' = $Order;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($parameter.name -ne 'Verbose') {
|
2019-09-16 09:33:57 -04:00
|
|
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, '$$null');
|
2019-09-13 05:44:37 -04:00
|
|
|
} else {
|
2019-09-16 09:33:57 -04:00
|
|
|
$Basket.Command[$Data.Name].vars.Add($parameter.Name, "");
|
2019-09-13 05:44:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Determine wether a parameter is required based on given syntax-information
|
|
|
|
|
if ($parameter.required -eq $TRUE) {
|
|
|
|
|
$Required = 'y';
|
|
|
|
|
} else {
|
|
|
|
|
$Required = 'n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$IcingaCustomVariable = [string]::Format('PowerShell_{0}_{1}', $parameter.type.name, $parameter.Name);
|
|
|
|
|
|
|
|
|
|
$DataListName = [string]::Format('PowerShell {0}', $parameter.Name)
|
2019-09-16 09:33:57 -04:00
|
|
|
|
2019-09-13 05:44:37 -04:00
|
|
|
if ($parameter.type.name -eq 'switch') {
|
2019-09-16 09:33:57 -04:00
|
|
|
$IcingaDataType='Boolean';
|
2019-09-13 05:44:37 -04:00
|
|
|
} elseif ($parameter.type.name -eq 'Object') {
|
|
|
|
|
if ($parameter.Name -eq 'Verbose') {
|
|
|
|
|
$IcingaDataType='Datalist'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$IcingaDataType='String';
|
|
|
|
|
|
|
|
|
|
} elseif ($parameter.type.name -eq 'Array') {
|
|
|
|
|
$IcingaDataType='Array';
|
|
|
|
|
} else {
|
|
|
|
|
$IcingaDataType='String';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($Basket.Datafield.ContainsKey('0') -eq $FALSE){
|
|
|
|
|
$Basket.Datafield.Add(
|
|
|
|
|
'0', @{
|
|
|
|
|
'varname' = 'PowerShell_switch_NoPerfData';
|
2019-09-16 09:33:57 -04:00
|
|
|
'caption' = 'Ignore Performance Data';
|
2019-09-13 10:23:34 -04:00
|
|
|
'description' = 'Specifies if the plugin will return performance data output or not';
|
2019-09-16 09:33:57 -04:00
|
|
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeBoolean';
|
2019-09-13 05:44:37 -04:00
|
|
|
'format' = $NULL;
|
|
|
|
|
'originalId' = '0';
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($Basket.Datafield.ContainsKey('1') -eq $FALSE){
|
|
|
|
|
$Basket.Datafield.Add(
|
|
|
|
|
'1', @{
|
2019-09-16 09:33:57 -04:00
|
|
|
'varname' = 'PowerShell_Object_Verbose';
|
2019-09-13 05:44:37 -04:00
|
|
|
'caption' = 'Verbose';
|
2019-09-13 10:23:34 -04:00
|
|
|
'description' = 'Specifies if the plugin will return performance data output or not';
|
2019-09-16 09:33:57 -04:00
|
|
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeString';
|
2019-09-13 05:44:37 -04:00
|
|
|
'format' = $NULL;
|
|
|
|
|
'originalId' = '1';
|
|
|
|
|
'settings' = @{
|
|
|
|
|
'datalist' = 'PowerShell Verbose';
|
|
|
|
|
'datatype' = 'string';
|
|
|
|
|
'behavior' = 'strict';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$IcingaDataType = [string]::Format('Icinga\Module\Director\DataType\DataType{0}', $IcingaDataType)
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
|
|
|
|
|
if ($Basket.Datafield.Values.varname -ne $IcingaCustomVariable) {
|
2019-09-13 05:44:37 -04:00
|
|
|
$Basket.Datafield.Add(
|
|
|
|
|
[string]$FieldID, @{
|
|
|
|
|
'varname' = $IcingaCustomVariable;
|
|
|
|
|
'caption' = $parameter.Name;
|
2019-09-13 10:23:34 -04:00
|
|
|
'description' = $parameter.Description.Text;
|
2019-09-13 05:44:37 -04:00
|
|
|
'datatype' = $IcingaDataType;
|
|
|
|
|
'format' = $NULL;
|
|
|
|
|
'originalId' = [string]$FieldID;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
if ($parameter.Name -eq 'Verbose') {
|
2019-09-13 05:44:37 -04:00
|
|
|
$Basket.Datafield[[string]$FieldID].Add(
|
|
|
|
|
'settings', @{
|
|
|
|
|
'behavior' = 'strict';
|
|
|
|
|
'datatype' = 'string';
|
|
|
|
|
'datalist' = $DataListName;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} elseif ($parameter.type.name -eq 'Object') {
|
|
|
|
|
$Basket.Datafield[[string]$FieldID].Add(
|
|
|
|
|
'settings', @{
|
|
|
|
|
'visbility' = 'visible';
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$Basket.Datafield[[string]$FieldID].Add(
|
|
|
|
|
'settings', @{
|
|
|
|
|
'visbility' = 'visible';
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Increment FieldID, so unique datafields are added.
|
|
|
|
|
[int]$FieldID = [int]$FieldID + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
# Increment FieldNumeration, so unique fields for a given command are added.
|
2019-09-13 05:44:37 -04:00
|
|
|
[int]$FieldNumeration = [int]$FieldNumeration + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Check whether or not noperfdata and verbose is set and add it if necessary
|
2019-09-16 09:33:57 -04:00
|
|
|
if ($Basket.Command[$Data.Name].arguments.ContainsKey('-Verbose') -eq $FALSE) {
|
|
|
|
|
$Basket.Command[$Data.Name].arguments.Add(
|
2019-09-13 05:44:37 -04:00
|
|
|
'-Verbose', @{
|
|
|
|
|
'value' = '$PowerShell_Object_Verbose$';
|
|
|
|
|
'order' = '99';
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
$Basket.Command[$Data.Name].vars.Add(
|
2019-09-13 05:44:37 -04:00
|
|
|
'PowerShell_Object_Verbose', "0"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($Basket.Datafield.Values.varname -eq $IcingaCustomVariable) {
|
|
|
|
|
} else {
|
|
|
|
|
$Basket.Datafield.Add(
|
|
|
|
|
[string]$FieldID, @{
|
|
|
|
|
'varname' = 'PowerShell_Object_Verbose';
|
|
|
|
|
'caption' = 'Verbose';
|
2019-09-13 10:23:34 -04:00
|
|
|
'description' = 'Increase the plugin output for more information on the received result.';
|
2019-09-13 05:44:37 -04:00
|
|
|
'datatype' = 'Icinga\Module\Director\DataType\DataTypeDatalist';
|
|
|
|
|
'format' = $NULL;
|
|
|
|
|
'originalId' = [string]$FieldID;
|
|
|
|
|
'settings' = @{
|
|
|
|
|
'behavior' = 'strict';
|
|
|
|
|
'data_type' = 'string';
|
|
|
|
|
'datalist' = 'PowerShell Verbose'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
if ($Basket.Command[$Data.Name].arguments.ContainsKey('-NoPerfData') -eq $FALSE) {
|
|
|
|
|
$Basket.Command[$Data.Name].arguments.Add(
|
2019-09-13 05:44:37 -04:00
|
|
|
'-NoPerfData', @{
|
|
|
|
|
'set_if' = '$PowerShell_switch_NoPerfData$';
|
|
|
|
|
'set_if_format' = 'string';
|
|
|
|
|
'order' = '99';
|
|
|
|
|
}
|
|
|
|
|
);
|
2019-09-16 09:33:57 -04:00
|
|
|
$Basket.Command[$Data.Name].vars.Add('PowerShell_switch_NoPerfData', $FALSE);
|
2019-09-13 05:44:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($check in $CheckName) {
|
|
|
|
|
[int]$FieldNumeration = 0;
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
$Data = (Get-Help $check)
|
|
|
|
|
|
|
|
|
|
foreach ($parameter in $Data.parameters.parameter){
|
2019-09-13 05:44:37 -04:00
|
|
|
$IcingaCustomVariable = [string]::Format('PowerShell_{0}_{1}', $parameter.type.name, $parameter.Name);
|
|
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
# Todo: Should we improve this? Actually the handling would be identical, we just need to assign
|
|
|
|
|
# the proper field for this
|
|
|
|
|
if ($IcingaCustomVariable -eq 'PowerShell_Int32_Verbose') {
|
|
|
|
|
$IcingaCustomVariable = 'PowerShell_Object_Verbose';
|
|
|
|
|
}
|
2019-09-13 05:44:37 -04:00
|
|
|
|
2019-09-16 09:33:57 -04:00
|
|
|
foreach ($DataFieldID in $Basket.Datafield.Keys) {
|
|
|
|
|
[string]$varname = $Basket.Datafield[$DataFieldID].varname;
|
|
|
|
|
if ([string]$varname -eq [string]$IcingaCustomVariable) {
|
|
|
|
|
$Basket.Command[$Data.Name].fields += @{
|
|
|
|
|
'datafield_id' = [int]$DataFieldID;
|
|
|
|
|
'is_required' = $Required;
|
|
|
|
|
'var_filter' = $NULL;
|
|
|
|
|
};
|
2019-09-13 05:44:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Build Filename with given Timestamp
|
|
|
|
|
$TimeStamp = (Get-Date -Format "MM-dd-yyyy-HH-mm-ffff");
|
|
|
|
|
$FileName = "PowerShell_CheckCommands_$TimeStamp.json";
|
|
|
|
|
|
|
|
|
|
# Generate JSON Output from Hashtable
|
|
|
|
|
$output = ConvertTo-Json -Depth 100 $Basket -Compress;
|
|
|
|
|
|
|
|
|
|
# Determine whether json output via powershell or in file (based on param -OutFile)
|
|
|
|
|
if ([string]::IsNullOrEmpty($OutFile) -eq $false) {
|
|
|
|
|
$OutFile = (Join-Path -Path $OutFile -ChildPath $FileName);
|
|
|
|
|
if ((Test-Path($OutFile)) -eq $false) {
|
|
|
|
|
New-Item -Path $OutFile -Force | Out-Null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((Test-Path($OutFile)) -eq $false) {
|
|
|
|
|
throw 'Failed to create specified directory. Please try again or use a different target location.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set-Content -Path $OutFile -Value $output;
|
|
|
|
|
|
|
|
|
|
# Output-Text
|
|
|
|
|
Write-Host "The following commands have been exported:"
|
|
|
|
|
foreach ($check in $CheckName) {
|
|
|
|
|
Write-Host "- '$check'";
|
|
|
|
|
}
|
|
|
|
|
Write-Host "JSON export created in '${OutFile}'"
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-Host "Check Command JSON for the following commands:"
|
|
|
|
|
foreach ($check in $CheckName) {
|
|
|
|
|
Write-Host "- '$check'"
|
|
|
|
|
}
|
|
|
|
|
Write-Host '############################################################';
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|