• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

PowerShell Script

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
WellingtonIS
Asked:
WellingtonIS
  • 11
  • 8
2 Solutions
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
WellingtonISAuthor Commented:
there's no script that Powershell runs to get computer models?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
WellingtonISAuthor Commented:
I'll try thanks!  Running it now.  But maybe it will take time. usually script just pops up.
0
 
WellingtonISAuthor Commented:
don't think it's working???  not  working as far as I can tell.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
WellingtonISAuthor Commented:
OK running thanks
0
 
WellingtonISAuthor Commented:
Not working.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That is? You don't get any result, or is the computer model info missing only?
0
 
WellingtonISAuthor Commented:
no results I left it run over  night
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
WellingtonISAuthor Commented:
ok I'll try.  Thanks so much!
0
 
WellingtonISAuthor Commented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Didn't get that WRM/WEL stuff, could you explain?
0
 
WellingtonISAuthor Commented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
WellingtonISAuthor Commented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
WellingtonISAuthor Commented:
Actually that did it. Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 11
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now