0

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?

1 Answer 1

1

$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")
Sign up to request clarification or add additional context in comments.

1 Comment

+1 Excellent, that's exactly what I was looking for. I thought that with the select I was simply directly returning the url, but it actually returns an object containing that member. Thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.