Andreas Grech
Andreas Grech

Reputation: 107950

Passing a Powershell object as a string parameter

I am currently trying to write the following Powershell script which, in SharePoint terms, retrieves the Central Administration url (retrieved in $adminUrl) and then opens an Internet Explorer window with that url.

I'm also appending another string to $adminUrl before passing it to the Navigate method:

$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

But I'm getting this exception when trying to do so:

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

Am I facing a casting issue here?

Upvotes: 0

Views: 2402

Answers (1)

Shay Levy
Shay Levy

Reputation: 126722

$adminUrl is an object with a url property so you need to use a sub-expression to pass:

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

or with a sub-expression:

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

You could pass the value of $adminUrl only if you expand the value of the Url property first:

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

Upvotes: 1

Related Questions