Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PowerShell Script

Posted on 2014-04-16
19
Medium Priority
?
605 Views
Last Modified: 2014-04-17
I'm using the following powershell script:
Get-ADComputer -Filter * -Properties * | select name,canonicalname,dnshostname,operatingsystem,OperatingSystemServicePack,operatingsystemversion,IPv4address | out-gridview


works great!  however, I'd like to know if it's possible to add the computer model to this?
0
Comment
Question by:WellingtonIS
  • 11
  • 8
19 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 40003994
AFAIK no. It would require to have that info in AD, and it isn't there. You can get OS info, but not about the hardware. So, for getting that info you would have to connect to each PC, and get the info from there.
0
 

Author Comment

by:WellingtonIS
ID: 40004007
there's no script that Powershell runs to get computer models?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40004066
Of course there are - using WMI or PS Remoting comes into mind. Again, the big difference between Get-ADComputer and WMI/Remoting is that you do not need to reach out to the machines you ask for for the former.
As a consequence, you don't get info about machines currently offline with WMI/Remoting.

Here is how you would get that info using WMI:
Get-ADComputer -Filter * -Properties * | select name,canonicalname,dnshostname,operatingsystem,OperatingSystemServicePack,operatingsystemversion,IPv4address | % {
  if (Test-Connection $_.Name -Count 1 -Quiet)
  {
    $info = Get-WmiObject Win32_ComputerSystem -Computer $_.Name
    $_ | Add-Member -PassThru NoteProperty Model "$($info.Manufacturer) ($info.Model)"
  } else {
    $_ | Add-Member -PassThru NoteProperty Model "(offline)"
  }
} |
  out-gridview

Open in new window

There is not much error checking - if the machine is online, but you do not have privileges, it will spit out errors, for example.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:WellingtonIS
ID: 40004131
I'll try thanks!  Running it now.  But maybe it will take time. usually script just pops up.
0
 

Author Comment

by:WellingtonIS
ID: 40004140
don't think it's working???  not  working as far as I can tell.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40004428
The result will only be displayed when the script execution is completed.
Try with this, including some progress indication:
Get-ADComputer -Filter * -Properties * |
  select name,canonicalname,dnshostname,operatingsystem,OperatingSystemServicePack,operatingsystemversion,IPv4address | % {
  Write-Host -Foreground Yellow "*** Testing PC $($_.Name) ***"
  if (Test-Connection $_.Name -Count 1 -Quiet)
  {
    $info = Get-WmiObject Win32_ComputerSystem -Computer $_.Name
    $_ | Add-Member -PassThru NoteProperty Model "$($info.Manufacturer) ($info.Model)"
  } else {
    $_ | Add-Member -PassThru NoteProperty Model "(offline)"
  }
} |
  out-gridview

Open in new window

0
 

Author Comment

by:WellingtonIS
ID: 40004471
OK running thanks
0
 

Author Comment

by:WellingtonIS
ID: 40006293
Not working.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40006509
That is? You don't get any result, or is the computer model info missing only?
0
 

Author Comment

by:WellingtonIS
ID: 40006545
no results I left it run over  night
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40006643
I've tested this script almost unchanged now on our 2008r2 domain with PS2, and got the expected results: data, "(offline)", or nothing if an error like "No RPC server available" (e.g. for NAS) occurs.
Even better, the gridview populates while the script executes - wasn't aware of that before.
The corrected version of the script is (one typo, so output for model info was slightly cryptic):
Get-ADComputer -Filter * -Properties * |
  select name,canonicalname,dnshostname,operatingsystem,OperatingSystemServicePack,operatingsystemversion,IPv4address | % {
  Write-Host -Foreground Yellow "*** Testing PC $($_.Name) ***"
  if (Test-Connection $_.Name -Count 1 -Quiet)
  {
    $info = Get-WmiObject Win32_ComputerSystem -Computer $_.Name
    $_ | Add-Member -PassThru NoteProperty Model "$($info.Manufacturer) $($info.Model)"
  } else {
    $_ | Add-Member -PassThru NoteProperty Model "(offline)"
  }
} |
  out-gridview

Open in new window

0
 

Author Comment

by:WellingtonIS
ID: 40006662
ok I'll try.  Thanks so much!
0
 

Author Comment

by:WellingtonIS
ID: 40006741
OK it ran but it didn't - the criteria I need starts with WRM and WEL I suspect it's too big and that's y now it's not running.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40006756
Didn't get that WRM/WEL stuff, could you explain?
0
 

Author Comment

by:WellingtonIS
ID: 40006782
I'll show you.  I have over 10,000 machines in this domain.  I only need machines in a specific OU - when this origional script runs It brings up everything in the domain, however, I only need specific machines in a specific OU - so after it runs I set the criteria to be WRM and WEL because all my machines begin that way - that how we distinguish one site from another.  the way this runs now, it's not able to bring up all the machine like the origional one did. Make sense? (My origional thought was to try to bring in the machine models because this script worked so well)
results.png
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40006817
How do you apply that filter? You should use the correct filter expression for the PC names, and optionally a search base for the OU if fixed:
Get-ADComputer -Filter { (name -like 'WEL*') -or (name -like 'WRM*') } -SearchBase 'OU=thisOU,dc=mydomain,dc=com'

Open in new window

Adding the model info isn't related to any filtering. The result of Get-ADComputer has to be what you want to ask for, and the only AD attribute required for the additional info is name. As long as those criteria are fulfilled, you get a result set, and if only with empty model info.

At this point either you have to reveal more real world info details, or try to troubleshoot yourself.
0
 

Author Comment

by:WellingtonIS
ID: 40006833
no the criteria is a button that pops up. that's this line select part.  I was never able to get it to work with name -like WEL or name like WRM..  Maybe I need to rethink this with a computer list instead...
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 2000 total points
ID: 40006886
The filter expression is working fine, if you use it exactly as shown (as a scriptblock, and using the '*' wildcard with -like). You always should try to get the filter working, as it is the fastest way to ask for restricted amount of data. If you get all machines, and then apply a filter with where-object, you are moving around a lot more data than needed.
And you should enumerate the properties you really want with Get-ADComputer, not using the star wildcard here.

Using a list of PCs won't help, unless you want to enumerate them manually, and I don't think so. From what you are telling me I'm getting the impression you are mixing up things, and hence not getting the desired results.

Anyway, the question is answered. You can try with a single, well-known machine in the first line:
Get-ADComputer -Properties * WellKnownMachine |
,,,

Open in new window

0
 

Author Closing Comment

by:WellingtonIS
ID: 40006942
Actually that did it. Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

916 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