Powershell 点符号不选择数据

标签 powershell powershell-2.0

我在让 Powershell 以我期望的方式运行时遇到问题。

我正在尝试使用 get-wmiobject win32_networkconnection 列出当前用户的映射驱动器,这样我就可以遍历这些驱动器。

当我运行 $var = get-wmiobject win32_networkconnection | select -expand localname 我得到的正是我所期望的:映射网络连接的驱动器号列表。

但是,当我运行 $var = (get-wmiobject win32_networkconnection).localname 时,我什么也没得到。它似乎没有正确选择属性。

这是有问题的,因为理想情况下,我想遍历所有驱动器,然后为每个驱动器选择各种属性。相反,似乎我将被迫拼凑一个迭代器,然后一次迭代所有变量(我认为这不是很优雅)。

我对 Powershell 不是很有经验,所以我可能遗漏了一些东西。但是,根据我的阅读,这应该有效。这是 get-wmiobject 的限制吗?

最佳答案

您尝试执行的操作仅适用于 PowerShell 3.0 和更新版本。官方文档非常含糊不清:

What's New in Windows PowerShell 3.0

Windows PowerShell Language Enhancements

Windows PowerShell 3.0 includes many features [...] The improvements include property enumeration, count and length properties on scalar objects, new redirection operators [...]

这篇博文更深入:New V3 Language Features

关于Powershell 点符号不选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31322548/

相关文章:

powershell - 如何在带有转义双引号的powershell字符串中传递变量

json - PowerShell 如何在解析的 JSON 上添加一些内容?

arrays - 移动数组中的项目

asp.net - OpenCover 显示没有结果 asp net core 461

powershell - 在PowerShell中使用数组删除文件夹?

arrays - 从 powershell 中的管道属性获取值(value)

windows - 从 Get-WinEvent 获取用户名

Powershell换行符不起作用我尝试过 `n "`n"'` n'

powershell - 我的 powershell 脚本在我预期的输出之前打印了 '1'。为什么?

powershell - 在 PowerShell 中搜索字符串中的特殊字符