?
Solved

Search for Windows 7 and 8 Machines only with this script

Posted on 2014-08-26
5
Medium Priority
?
219 Views
Last Modified: 2014-08-30
Hi ALL

Subsun and Qlemo helped me with this last night .. I want to continue with this same script and add two more features.

1. Search the entire domain for Windows 7 and 8 machines only and get the output from the script below.
2. Have the option to modify the script so I can search a particular OU only instead of the entire domain .

As always .. thank you for all the help !

function get-localusers {
 param(
 [Parameter(Mandatory=$true,valuefrompipeline=$true)]
 [string]$strComputer
 )
 
 $Select = "Name","Class","Parent" | %{  
 Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember('$_', 'GetProperty', `$Null, `$_, `$Null) }}"
 }
 
 If (Test-Connection $strComputer -Count 2 -Quiet){
  try{
  $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
  $AdminGroup = $computer.psbase.children.find("Administrators")
  $Adminmembers= $AdminGroup.psbase.invoke("Members") | Select $Select
    foreach ($admin in $Adminmembers) {
    $admin | Select @{N="ComputerName";E={$strComputer}},@{N="Administrators";E={"$(($_.parent -SPLIT "/")[-1])\$($_.Name)"}},Class,Parent
    }
 }catch{ 
 "" | Select @{N="ComputerName";E={$strComputer}},@{N="Administrators";E={"Access Denied"}},Class,Parent
 }
 }
Else {
 "" | Select @{N="ComputerName";E={$strComputer}},@{N="Administrators";E={"Not able to Ping"}},Class,Parent
 }
}
Get-Content "C:\Powershell\Servers.txt" | get-localusers | Select ComputerName,Administrators,Class,Parent | Export-Csv "C:\Powershell\LocalAdm$((get-date).toString('MM-dd-yyyy')).csv" -NTI

Open in new window

0
Comment
Question by:MilesLogan
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 40286149
To Get all Win7 & 8 computers
Get-ADComputer -f {OperatingSystem -like "Windows 8*" -or OperatingSystem -like "Windows 7*"} | %{$_.Name} | Get-localusers | Select ComputerName,Administrators,Class,Parent | Export-Csv "C:\Powershell\LocalAdm$((get-date).toString('MM-dd-yyyy')).csv" -NTI

Open in new window


Use -SearchBase parameter to search in specific OU..

Hope you have read my article which explains the same.. :-)
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/A_12657-Active-Directory-module-PowerShell-cmdlets-Part-2.html
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 40286181
Hi Subsun .. where would I add this to the existing script ?


Get-ADComputer -f {OperatingSystem -like "Windows 8*" -or OperatingSystem -like "Windows 7*"} | %{$_.Name} | Get-localusers | Select ComputerName,Administrators,Class,Parent | Export-Csv "C:\Powershell\LocalAdm$((get-date).toString('MM-dd-yyyy')).csv" -NTI
0
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 40286227
Replace last line of code (line 27)..
0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 40295040
Sorry for the late reply .. Worked perfect 👌  .. Thanks
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40295160
No problem.. :-)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
Loops Section Overview

864 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