Solved

Powershell multiple queries

Posted on 2014-11-27
5
108 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 28

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 68

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 68

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
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 …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now