Solved

PowerShell Script

Posted on 2014-04-16
19
583 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 68

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 68

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
 

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 68

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 68

Expert Comment

by:Qlemo
ID: 40006509
That is? You don't get any result, or is the computer model info missing only?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Accepted Solution

by:
Qlemo earned 500 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 68

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 68

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 68

Assisted Solution

by:Qlemo
Qlemo earned 500 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

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 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 …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

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

16 Experts available now in Live!

Get 1:1 Help Now