Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outputting PSBound Parameters

I'd like to output the values of whatever parameters have been passed to my script for including in an email.

I've tried this:

foreach ($psbp in $PSBoundParameters)
{
    $messageBody += $psbp | out-string + "`r`n"
}

But it didn't work. Can someone give me a hand?

like image 214
Carl Chipman Avatar asked Apr 26 '12 06:04

Carl Chipman


People also ask

What is the use of $psboundparameters?

This variable is present if a script or function you create that contains user-populated parameters. In other words, if you've got a script or function using the param () statement with one or more parameters inside and you've passed arguments to these parameters, the $PsBoundParameters variable will always be available.

What are the supported parameters and their defaults for outputters?

The supported parameters and their defaults are: This parameter specifies the column separator character that separates columns in the file. The default column separator is ',' (comma). The delimiter parameter is not available for Outputters.Csv () and Outputters.Tsv ().

Can the outputter generate a BOM for the encoding?

Unfortunately, the outputter cannot generate a BOM for the encoding, since the parallel processing of the outputter does not know which split is going to be the beginning of the output file. Since the outputter should not generate BOMs for every split, the built-in outputters are not adding BOMs. Encoding. [ASCII]

Where is the delimiter parameter for the built-in outputters?

The delimiter parameter is not available for Outputters.Csv () and Outputters.Tsv (). Note that per default, the built-in outputters are quoting string values. Thus any delimiter inside a value will be protected. If quoting is turned off, then the escaping needs to be turned on to protect the delimiter character inside a value.


1 Answers

$PSBoundParameters is a hash table, use GetEnumerator to unfold its items

foreach($psbp in $PSBoundParameters.GetEnumerator())
{
    "Key={0} Value={1}" -f $psbp.Key,$psbp.Value
}




function Get-PSBoundParameters
{
    [CmdletBinding()]    
    Param($param1,$param2,$param3)

    foreach($psbp in $PSBoundParameters.GetEnumerator())
    {
            "Key={0} Value={1}" -f $psbp.Key,$psbp.Value
    }
}


PS> Get-PSBoundParameters p1 p2 p3 | ft -a

Key=param1 Value=p1
Key=param2 Value=p2
Key=param3 Value=p3
like image 101
Shay Levy Avatar answered Oct 14 '22 06:10

Shay Levy