我是一个Powershell新手,试图枚举pscx模块中的所有pscx。我以前在powershell中使用过foreach,但它似乎没有处理来自ExportedCmdlets的键/值输出。
到目前为止,这就是我所拥有的:
$cmdLets = (Get-Module pscx).ExportedCmdlets
echo $cmdLets
echo '-----------------'
# This is where the script breaks - $cmdLet is the entire set of $cmdLets
foreach ( $cmdLet in ($cmdLets) ) {
echo $cmdLet
echo 'next'
}如何使$cmdLet成为$cmdLets中的一个项目?
更具体地说,如何正确地迭代键/值输出?
发布于 2017-09-18 17:08:23
使用$cmdLets.GetEnumerator()
foreach ( $cmdLet in $cmdLets.GetEnumerator() ) {
echo $cmdLet
echo 'next'
}发布于 2017-09-18 17:05:45
使用keys属性,即:
$cmdLets = (Get-Module pscx).ExportedCmdlets.Keys
echo $cmdLets
echo '-----------------'
foreach ( $cmdLet in ($cmdLets) ) {
echo $cmdLet
echo 'next'
}https://stackoverflow.com/questions/46284686
复制相似问题