Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Powershell noteproperty用作变量中的文本字符串_Powershell_Pscustomobject - Fatal编程技术网

将Powershell noteproperty用作变量中的文本字符串

将Powershell noteproperty用作变量中的文本字符串,powershell,pscustomobject,Powershell,Pscustomobject,我使用Invoke Restmethod在名为data的属性中下载了一些数据,Powershell将这些数据存储在PSCustomObject中 我需要使用返回数据中某个项的值作为另一个命令的变量。我已成功地从Get Member中选择了object-向下扩展到以下输出: Name MemberType Definition ---- ---------- ---------- E

我使用Invoke Restmethod在名为data的属性中下载了一些数据,Powershell将这些数据存储在PSCustomObject中

我需要使用返回数据中某个项的值作为另一个命令的变量。我已成功地从Get Member中选择了object-向下扩展到以下输出:

Name        MemberType   Definition                    
----        ----------   ----------                    
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()             
GetType     Method       type GetType()                
ToString    Method       string ToString()             
id          NoteProperty System.Int32 id=999 
我需要做的是获取ID noteproperty的值-999-并将其作为字符串的一部分传递给新变量,例如:

$newVar = "sometext" + 999 + "moretext"
大量的选择字符串或输出字符串等都没有帮助。脚本编写并不是我的强项,所以我甚至不能确定我是否正确地表达了我想要的内容——如果是这样的话,请道歉


非常感谢任何帮助

我不确定您的代码和外观,因此我根据描述创建了以下静态近似值:

$data = New-Object PSCustomObject
$data | Add-Member -Type NoteProperty -Name Id -Value 999
$restResponse = New-Object PSCustomObject
$restResponse | Add-Member -Type NoteProperty -Name data -Value $data
如果不匹配,请澄清。您可以按如下方式获得Id值

$restResponse.data.Id
将其分配给另一个变量

$newVar = "sometext" + $restResponse.data.Id + "moretext"
$newVar
如果您的REST响应是数据对象的集合,则遍历它们

$restResponse.data | Foreach-Object { "sometext" + $_.Id + "moretext" }

我倾向于使用
$output | select*,@{n='test';e={[string]$\.test}
-exclude-properties-test


如果排除未激活,它将抱怨它已经存在。对于这样简单的任务,我通常使用select表达式来实时处理数据,而不是
psCustomObject
,谢谢。我想我盯着这个看太久了!