2017-03-04 42 views
1

我有以下几点:访问PowerShell的属性与空间名

$test = Test-CsWebScheduler -TargetFqdn "pool.int.contoso.com" 
Write-Output $test 

Target Fqdn : pool.int.contoso.com 
Target Uri : https://pool.int.contoso.com/Scheduler/ 
Result  : Failure 
Latency  : 00:00:00 
Error Message : Scheduling conference at 
       https://pool.int.contoso.com/Scheduler/Handler/WebSchedulerHandler.ashx failed 
       with status Failure. 

Diagnosis  : 

现在的问题是:

我怎样才能访问“错误信息”,“目标URI”或“目标FQDN “?我可以通过访问结果:

Write-Output $test.result 
Failure 

没有问题,但该有的都有了里面的空间,我haven't找到了一种方法来访问它们。我尝试以下(发现here):

Write-Output $test."Target Uri" 

Write-Output $test.{Target Uri} 

我也试过如下:

$test | Select-Object -Property "Target Uri" 

Write-Output ($test."Target Uri") 

或非常简单:

$test."Target Uri" 

但这不起作用,我没有得到回值(也没有错误)。唯一的错误消息我得到的是,当我使用:

$test | select -ExpandProperty "Target Uri" 

select : Property "Target Uri" cannot be found. 
At line:1 char:9 
+ $test | select -ExpandProperty "Target Uri" 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (Microsoft.Rtc.S...s.WebTaskOutput:PSObject) [Selec 
    t-Object], PSArgumentException 
    + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCom 
    mand 

有没有人有一个想法如何,我可以访问(没有倾销,要一个临时文件,并解析它)?

更新01:

这里要求是从$测试输出|克

$test | gm 

    TypeName: Microsoft.Rtc.SyntheticTransactions.WebTaskOutput 

Name   MemberType Definition 
----   ---------- ---------- 
Equals   Method  bool Equals(System.Object obj) 
GetHashCode Method  int GetHashCode() 
GetType  Method  type GetType() 
ToString  Method  string ToString() 
Diagnosis  Property string Diagnosis {get;} 
Error   Property string Error {get;} 
Latency  Property timespan Latency {get;} 
Result   Property Microsoft.Rtc.SyntheticTransactions.ResultStatus Result {get;} 
TargetFqdn  Property string TargetFqdn {get;} 
TargetUri  Property string TargetUri {get;} 
WorkflowLogger Property Microsoft.Rtc.SyntheticTransactions.Logging.SyntheticTransactionsWorkf... 
+2

'$测试 “目标URI”' - 应做工精细;你可以粘贴(更新问题)从'$ test |输出gm'? – 4c74356b41

+0

是的,我也希望如此,但正如上面所写,情况并非如此。 – BastianW

+0

当我使用'Write-Output($ test。“Target Uri”)'或'$ test。“时,没有什么区别。Target Uri”'...'$ test | gm'现在添加到我的原始发布。 – BastianW

回答

0

正如在评论中提到的:使用输出中显示的“名称”并不意味着它们与真实属性名称相同。但是,使用Get-Member (or the short abbreviation GM)时,可以检查变量中存储的实际属性名称。

因此,使用

$test | Get-Member 

显示, “目标URI” 是 “targetURI中”:

[...] 
TargetUri  Property string TargetUri {get;} 
[...] 

因此,使用:

$test.TargetUri 

在这里解决了这个问题。

0

作为管道将$测试变量时得到-构件看出

提供表明目标URI属性实际上是一个字,所以简单地使用下面将用于工作的输出你在你的脚本中。

$test.TargetUri 
0

尝试进入这样的值:

$test.PSObject.Properties["Target Uri"].Value