Link to home
Start Free TrialLog in
Avatar of WellingtonIS
WellingtonIS

asked on

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?
Avatar of Qlemo
Qlemo
Flag of Germany image

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.
Avatar of WellingtonIS
WellingtonIS

ASKER

there's no script that Powershell runs to get computer models?
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.
I'll try thanks!  Running it now.  But maybe it will take time. usually script just pops up.
don't think it's working???  not  working as far as I can tell.
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

OK running thanks
Not working.
That is? You don't get any result, or is the computer model info missing only?
no results I left it run over  night
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok I'll try.  Thanks so much!
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.
Didn't get that WRM/WEL stuff, could you explain?
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
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.
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...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually that did it. Thanks!