Solved

Powershell multiple queries

Posted on 2014-11-27
5
113 Views
Last Modified: 2015-01-23
Hi all, is it possible to query multiple objects and have the all returned for example im looking to get a report on
SAMAccountName,name.IPv4Address,Created,Modified,OperatingSystemVersion,OperatingSystem,OperatingSystemServicePack,LastLogonTimeStamp

thanks
0
Comment
Question by:cwstad2
5 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 250 total points
ID: 40468887
You can run all the separate queries then store the results in a hash table and then output to the desired format.

The info you have above, I assume you are querying this information for a computers ?
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 40469552
As an example you can use this :
function get-objvalues
{
$computer=hostname
$totalprocesses = (Get-Process).count

return $computer, $totalprocesses
}
$pc,$tprc = get-objvalues
Write-Host "PC - $pc      Processes Count - $tprc"

Open in new window

Or

$results = get-objvalues
Write-Host "PC - $($results.item(0))      Processes Count - $($results[1])"

Open in new window

0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 40469613
Using an array is far from being a good idea. You loose all "property" info, and those are what makes PowerShell a rich tool.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40469758
What becraig meant was, translated to the example by RMA:
function get-objectvalues
{
   New-Object PsObject -Property @{
       ComputerName = $env:ComputerName
       TotalProcesses   = (Get-Process).Count
  }
}

$results = get-objectvalues
$results | format-table -auto
Write-Host "$($results.ComputerName) has $($results.TotalProcesses) processes running"

Open in new window

0
 
LVL 15

Author Closing Comment

by:cwstad2
ID: 40565969
sorry for the delay guys. Appreciate the help
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Set OWA language and time zone in Exchange for individuals, all users or per database.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question