首页 > 解决方案 > Get-MsolUser 的所有参数放入数组

问题描述

想要将 Get-MsolUser 支持的所有参数的名称扔到一个数组中,以便能够动态地从用户那里获取不同的信息。

Get-Command Get-MsolUser

上面的命令不显示参数,只显示命令本身。

标签: powershellreflectionparameters

解决方案


您可以运行以下命令,它只是链接成员访问运算符.

$array = (Get-Command Get-MSolUser).Parameters.Values.Name

Parameters是具有内置Values属性的 Dictionary 对象。该属性是一个集合,其中包含有关每个参数的属性。由于您只需要名称,因此您可以简单地访问该Name属性。

如果你想排除某些参数,我只是介绍一个排除列表。

$exclude = 'Debug','ErrorAction','ErrorVariable','InformationAction','InformationVariable','OutVariable','OutBuffer','PipelineVariable','Verbose','WarningAction','WarningVariable'

((Get-Command Get-MSolUser).Parameters.Values | Where Name -notin $exclude).Name

推荐阅读