MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Pass Service Application ID into PowerShell variable

  Asked By: Tracie    Date: Aug 15    Category: MOSS    Views: 3009

While I understand that this is a SharePoint forum, and I have a PowerShell
question, this does related to SharePoint and my Google-Fu and Web-Jitsu are
useless to me at this point.

In a PowerShell script that I am writing, I need to capture the ID of a Single
Service Application and store that in a variable to use later.

The following line will get me narrowed down to a single service application,
but it lists the Display Name, Type Name, and ID. I need to narrow it down to
just the ID.

$ID = (Get-SPServiceApplication | where-object {$_.TypeName -eq "<Service
Application Type goes here>"})

I saw something somewhere once but I am having absolutely no luck finding it

I would greatly appreciate any help that anyone can offer on this one.



4 Answers Found

Answer #1    Answered By: Ali Javed     Answered On: Aug 15

What are you going to use that $ID variable for? Whatever you use it for
should be able to take the SPServiceApplication object the way it is. If
you need the ID as a string, and it's not getting converted correctly
you could get it like this:


You could also restrict the $ID variable to the object's ID like this:

$ID = (Get-SPServiceApplication | where-object {$_.TypeName -eq

Application Type goes here>"} | select ID

That's kind of clunky though.

You could also do this to cast $ID as a string:

[string]$ID = Get-SPServiceApplication | where-object {$_.TypeName -eq
"<Service Application Type goes here>"} | select ID

Answer #2    Answered By: Karrie Wooten     Answered On: Aug 15

I don't care if it is clunky as long as it works. That is exactly what I needed.

Answer #3    Answered By: Alan West     Answered On: Aug 15

You can do it in two lines...

> $ServiceApp = (Get-SPServiceApplication | where-object {$_.TypeName -eq
"<Service Application Type goes here>"})
> $ServiceApp.Id

That should do it.

Answer #4    Answered By: Maribel Todd     Answered On: Aug 15

Refactored it onto one line. Sorry about the dual reply...

$ID = (Get-SPServiceApplication | where-object {$_.TypeName -eq "<Service
Application Type goes here>"}).Id

Simply add the ".Id" to the end. The expression in the parens equates to the
service application object, so you can easily access its Id field.

Didn't find what you were looking for? Find more on Pass Service Application ID into PowerShell variable Or get search suggestion and latest updates.