header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
FindRegistrySetting.ps1
Last Post 20 Sep 2010 02:27 PM by George Howarth. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
GriffUser is Offline
New Member
New Member
Posts:1
Avatar

--
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 HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    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.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer