cmd. exe powershell HashTable

Using CMD When exe is called, is there a method in the power shell that can pass hashtable as a parameter?

I want to call this script:

powershell "& 'C:\path\to\file.ps1 arg1 arg2 arg3 arg4'"

Where arg4 is hashtable Is that possible?

Solution

Give a script like this (foo. PS1):

param($a1,$a2,$a3,[hashtable]$a4)

"a1 is $a1"
"a2 is $a2"
"a3 is $a3"
"a4 is "
$a4

You can from CMD Exe calls it, specifying the hash table as the fourth parameter:

C:\> powershell -command "& {c:\foo.ps1 1 2 three @{name='John';age=45}}"
a1 is 1
a2 is 2
a3 is three
a4 is

Name                           Value
----                           -----
name                           John
age                            45
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>