Solved

PowerShell Script

Posted on 2014-04-16
19
588 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 69

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 69

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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 69

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 69

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 69

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 69

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 69

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 69

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Matching items in two arrays 3 30
Office 365 enable Skype for all users with E3 License 3 34
Exchange 2010 internal URLs 2 40
Problem to setup GUI 11 27
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Set OWA language and time zone in Exchange for individuals, all users or per database.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

805 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