arrays - “{}”中带有字符串/ArrayValue 的 PowerShell 新 Pipline 变量
问题描述
我需要一个解决方案来创建某种格式的数组。
背景 我导出一个 SharePoint 列表并从一个 XML 文件中获取我的字段。
要导出的命令(通过 PnP)如下:
$AllSPListItems = Get-PnPListItem $SharePointListName
$ItemsSelection = @{ L = "ID"; E = { $_["ID"] } },@{ L = "SP_SiteURL"; E = { $_["SP_SiteURL"] } }
$AllSPListItems | Select $ItemsSelection | Export-Csv -Path "C:\Temp\XYZ.csv"
那行得通,但这就是我想要的:
$ItemsSelection = @{ L = "$FieldDisplayName[0]"; E = { $_[$FieldURLName[0]] } },@{ L = "$FieldDisplayName[1]"; E = { $_[$FieldURLName[1]] } } }
我从我的 XML 中获取$FieldDisplayName
和变量。$FieldURLName
不幸的是,我只得到以下输出:
@{ L = "ID"; E = { $_[$FieldURLName[0]] } },@{ L = "SP_SiteURL"; E = { $_[$FieldURLName[1]] } } }
Name Value
---- -----
E $FieldURLName[0]
L ID
E $FieldURLName[1]
L SP_SiteURL
那么我怎样才能得到“E”的值,而不是文本呢?变量无法解析。
非常感谢!
解决方案
So how can I get the value of "E", not the text?
You get the text of the E
scriptblock because it hasn't executed yet - that only happens once you use it with Select-Object
.
To get the correct label names, remove the "
quotes around the label expression:
$ItemsSelection = @{ L = $FieldDisplayName[0]; E = { $_[$FieldURLName[0]] } },@{ L = $FieldDisplayName[1]; E = { $_[$FieldURLName[1]] } } }
$AllSPListItems | Select $ItemsSelection | Export-Csv -Path "C:\Temp\XYZ.csv"
推荐阅读
- react-native - 如何允许用户在 React Native 应用程序中调整字体大小?
- c++ - 将类注入派生
- javascript - 显示默认外观的 IE 自定义输入
- java - 在 Java 中没有用户名的 Mac 上文件的路径
- visual-studio-code - VS Code 中基于语言的设置不起作用
- scala - 如何在 spark scala 中获得 groupby 的输出如下
- docker - Docker DNS 全限定域名
- sql - SQL:按日期对列进行排名/分组
- firebase - 当应用程序已在运行且使用 Firebase 动态链接时导航不起作用
- ssh - 如何在使用 psftp 获取期间排除子目录?