MilesLogan
asked on
Search for Windows 7 and 8 Machines only with this script
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 !
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
ASKER
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,Administrator s,Class,Pa rent | Export-Csv "C:\Powershell\LocalAdm$(( get-date). toString(' MM-dd-yyyy ')).csv" -NTI
Get-ADComputer -f {OperatingSystem -like "Windows 8*" -or OperatingSystem -like "Windows 7*"} | %{$_.Name} | Get-localusers | Select ComputerName,Administrator
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the late reply .. Worked perfect š Ā .. Thanks
No problem.. :-)
Open in new window
Use -SearchBase parameter to search in specific OU..
Hope you have read my article which explains the same.. :-)
https://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/A_12657-Active-Directory-module-PowerShell-cmdlets-Part-2.html