Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hash Table or 2 Dimensional Array 1

Status
Not open for further replies.

peterlyttle

Technical User
Nov 6, 2006
139
GB
Hello, just started working with powershell today and am wondering how I would do the following -

The Get-Service command will return 3 columns and many rows, is there any way I can input this into an array so that I dont have to run the Get-Service command multiple times?

From this I would then like to search the array for a value eg "DHCP Client" and then print the whole row in the array.

Anyone have any ideas?

Cheers,
Peter
 
Welcome to PowerShell.

You could just use a variable to hold the returned objects:
Code:
$s = get-service
Then you'd have access to all the properties and can select what you want:
Code:
$s | where-object {$_.DisplayName -match 'DHCP'} | select-object Name, Status, DisplayName
or
Code:
$s | where {$_.DisplayName -match 'DHCP'} | select Name, Status, ServicesDependedOn
or
Code:
$s | where {$_.Status -eq 'Running'} | select Name, CanStop

What are you looking to do with the data?

 
Ah excellent, the where-object was what I was after. How do I do a -

where-object {$_.DisplayName -match 'DHCP' AND $_.Status -match 'Running'}

So basically what im asking how do I do AND and OR statements on this line?
 
Just came across my answer its -and / -or

Thanks again for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top