internal/functions/convert-hashtoargstring.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Convert HashTable into an array
 
.DESCRIPTION
Convert HashTable into an array of Key and Value
 
.PARAMETER Inputs
The HashTable object that you want to work against
 
.PARAMETER KeyPrefix
The prefix that you want to append to the key of the HashTable
 
The default value is "-"
 
.PARAMETER ValuePrefix
The prefix that you want to append to the value of the HashTable
 
The default value is " "
 
.EXAMPLE
$params = @{DatabaseServer = "Localhost"; DatabaseName = "MicrosoftDynamicsAx_model"}
$arguments = Convert-HashToArgString -Inputs $params
 
This will convert the $params into an array of strings, each with the Key and Value.
 
.NOTES
Author: Mötz Jensen (@Splaxi)
 
#>

function Convert-HashToArgString {
    [CmdletBinding()]
    param (
        [HashTable] $InputObject,

        [string] $KeyPrefix = "-",

        [string] $ValuePrefix = " "
    )

    $InputObject.Keys | ForEach-Object { "$KeyPrefix$($_)$ValuePrefix`"$($InputObject.Item($_))`""}
}