Solved

Powershell multiple queries

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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