Solved

Powershell multiple queries

Posted on 2014-11-27
5
117 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 19

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 70

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 70

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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…

617 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