Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
Peer Review
FindRegistrySetting.ps1
Last Post 20 Sep 2010 02:27 PM by
George Howarth
. 1 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Griff
New Member
Posts:1
17 Sep 2010 05:48 AM
Hello all,
I am trying to write a script to query the registry for a list of comptuers and put the information into a csv.
The trouble I am having is with the ping.send or test-connection when I hit a machine that isn't in dns.
I can't get it to continue gracefully no matter what I try so I am hoping one of you Posh Guru's will point out what I could be doing.
Thanks to Shay Levy and his PSRemoteRegistry Module. I like the test-connection -computername $computer -quiet as it will continue on false but for some reason i can't pass true into the rest of the script.
Thanks.
cls
$ErrorActionPreference = "SilentlyContinue"
#Get a list of all computers you want to scan and put them in a csv
$Computers = Get-Content C:\ScriptTest\comp2scan.csv
$AllComputers = @()
$PermissionFailure = @()
$WMIFailure = @()
$ComputerObj = "" | Select-Object "Computer Name","Has Auto Login Enabled"
$AllComputers += $ComputerObj
foreach ($Computer in $Computers)
{
#Ping each server to check that it's alive
$ping = ""
$ping = Test-Connection -ComputerName $Computer -Quiet -Count 1
if ($ping.Value -eq "True")
{
#Read registry keys This can be modified depending on the key value you are looking for.
Write-Host "Working on $Computer"
$key = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
if (!$?)
{
$RegistryFailureObj = new-object psObject
$RegistryFailureObj | Add-Member -MemberType noteproperty -name "Computer Name" -Value $Computer
$RegistryFailureObj | Add-Member -membertype noteproperty -name "Registry Failure" -Value $error[0].tostring()
$PermissionFailure += $RegistryFailureObj
}
else
{#I am looking for auto logins here
$regKey = Get-RegString -ComputerName $computer -Key $key -Value AutoAdminLogon
if ($regKey.Data -match "1")
{
$nodcheck = $true
$ComputerObj | Add-Member -membertype noteproperty -name "Computer Name" -Value $Computer -Force
$ComputerObj | Add-Member -membertype noteproperty -name "Has Auto Login Enabled" -Value "True" -Force
}
}
if ($nodcheck -eq $false)
{
$ComputerObj | Add-Member -membertype noteproperty -name "Computer Name" -Value $Computer -Force
$ComputerObj | Add-Member -membertype noteproperty -name "Has Auto Logon Disabled" -Value "False" -Force
}
}
$AllComputers += $ComputerObj
}
$AllComputers | Export-Csv C:\ScriptTest\AutoLogonStatus.csv -Force -NoTypeInformation -Encoding ascii
$PermissionFailure | Export-Csv C:\ScriptTest\AutoLogonRegistryFailures.csv -Force -NoTypeInformation
$WMIFailure | Export-Csv C:\ScriptTest\AutoLogonWMIFailures.csv -Force –NoTypeInformation
George Howarth
Basic Member
Posts:360
20 Sep 2010 02:27 PM
There is an error with the way you are using Test-Connection. Change it to this:
foreach ($Computer in $Computers)
{
#Ping each server to check that it's alive
$success = Test-Connection -ComputerName $Computer -Quiet -Count 1
if ($success)
{
...
When you specify the -Quiet switch, Test-Connection returns a Boolean, not a PingReply object.
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Active Directory
--Exchange Server
--Lync Server
--SharePoint
--SQL Server
--System Center
--Non-Microsoft Products
--Books, Tools, and Videos
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
Peer Review
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2