2012-07-03 65 views
0

我目前正在尝试编写以下Powershell脚本,其中以SharePoint术语检索管理中心URL(在$adminUrl中检索),然后使用该URL打开Internet Explorer窗口。将Powershell对象作为字符串参数传递

我还追加另一个字符串$adminUrl将它传递给Navigate方法之前:

$adminUrl = Get-spwebapplication -includecentraladministration | where {$_.DisplayName -eq "SharePoint Central Administration v4"} | select Url 

$ie = New-Object -ComObject InternetExplorer.Application 
$ie.Navigate($adminUrl + "/someurl") # <= Trying to pass the url here 
$ie.Visible = $true 

但试图这样做时,我得到这个异常:

Cannot find an overload for "Navigate" and the argument count: "1". 
At \\a\setup.ps1:9 char:1 
+ $ie.Navigate($adminUrl) 
+ ~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodException 
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest 

上午我在这里面临铸造问题?

回答

1

$ adminUrl是一个url属性的对象,所以你需要使用一个子表达式来传递:

$ie.Navigate($adminUrl.Url + "/someurl") 

或子表达式:

$ie.Navigate("$($adminUrl.Url)/someurl") 

你可以通过仅当您首先扩大Url属性的值时,才需要$ adminUrl的值:

...| select -ExpandProperty Url 
$ie.Navigate("$adminUrl/someurl") 
+0

+1非常好,那就是我一直在寻找的。我以为用select可以直接返回url,但实际上它返回的是包含该成员的对象。感谢您的回答。 –

相关问题