Announcement

Collapse
No announcement yet.

powershell guru's

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    powershell guru's

    hey all... i have never used powershell - still chose to use vbscript but I gave a stab. It seems that this code works and maybe not all that is needed.

    I had to pull some reg keys, services with states and local users status.

    My script works and dumps it into a txt file but I wanted to throw it into a html as would look ever so much better...

    can someone, who may be bored (lol) be willing to help me out?

    end result is a 2 row table...

    Item......................Result

    this actually just dumps them all into 1 row but hey html!!!!
    Code:
    # Static array of registry keys
    $RegKeys = @("DisableNotificationCenter","AutoConfiURL","HibernateEnabled","HideSCAHealth","NoDriveTypeAutoRun","TurnOffSidebar","EnableBaloonTips","UseDomainNameDevolution","DomainNameDevolutionlevel","*.one.ads","*","SearchOrderConfig","NoAutoRebootWithLoggedOnUsers","DisabledComponents","fAllowToGetHelp","fDenyTSConnections","EnableLUA","dontdisplaylastusername")
    #Static array of service names
    $Services = @("LanmanServer","MPSSVC","WinDefend","WSCSVC","TRKWKS","NAPAGENT","WUAUSERV")
    #Static array of users 
    $Users = @("LCSAdmin","Guest")
    
    #Registry Keys
    $dnc = 'HKCU:\Software\Policies\Microsoft\Windows\Explorer'
    if (Test-Path $dnc) {$dnc = (Get-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Windows\Explorer").DisableNotificationCenter}
    else {$dnc = "Key not Found"}
    $acu = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
    if (Test-Path $acu) {$acu = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings").AutoConfigURL}
    else {$acu = "Key not Found"}
    $he = 'HKLM:\SYSTEM\CurrentControlSet\Control\Power'
    if (Test-Path $he) {$he = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power").HibernateEnabled}
    else {$he = "Key not Found"}
    $hscah = 'HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer'
    if (Test-Path $hscah) {$hscah = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer").HideSCAHealth}
    else {$hscah = "Key not Found"}
    $ndtar = 'HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer'
    if (Test-Path $ndtar) {$ndtar = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer").NoDriveTypeAutoRun}
    else {$ndtar = "Key not Found"}
    $tos = 'HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Windows\Sidebar'
    if (Test-Path $tos) {$tos = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Windows\Sidebar").TurnOffSidebar}
    else {$tos = "Key not Found"}
    $ebt = 'HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer\Advanced'
    if (Test-Path $ebt) {$ebt = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer\Advanced").EnableBaloonTips}
    else {$ebt = "Key not Found"}
    $udnd = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient'
    if (Test-Path $udnd) {$udnd = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient").UseDomainNameDevolution}
    else {$udnd = "Key not Found"}
    $dndl = 'HKLM:\SYSTEM\CURRENTCONTROLSET\SERVICES\Dnscache\Parameters'
    if (Test-Path $dndl) {$dndl = (Get-ItemProperty -Path "HKLM:\SYSTEM\CURRENTCONTROLSET\SERVICES\Dnscache\Parameters").DomainNameDevolutionlevel}
    else {$dndl = "Key not Found"}
    $oads = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\bms.com\*.one.ads'
    if (Test-Path $oads) {$oads = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\bms.com\*.one.ads")."*"}
    else {$oads = "Key not Found"}
    $ads = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\bms.com\*.one.ads'
    if (Test-Path $ads) {$ads = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\bms.com\")."*"}
    else {$ads = "Key not Found"}
    $soc = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching'
    if (Test-Path $soc) {$soc = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching").SearchOrderConfig}
    else {$soc = "Key not Found"}
    $narwlou = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU'
    if (Test-Path $narwlou) {$narwlou = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU").NoAutoRebootWithLoggedOnUsers}
    else {$narwlou = "Key not Found"}
    $dc = 'HKLM:\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters'
    if (Test-Path $dc) {$dc = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters").DisabledComponents}
    else {$dc = "Key not Found"}
    $atgh = 'HKLM:\SYSTEM\CurrentControlSet\Control\Remote Assistance'
    if (Test-Path $atgh) {$atgh = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Remote Assistance").fAllowToGetHelp}
    else {$atgh = "Key not Found"}
    $dtsc = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services'
    if (Test-Path $dtsc) {$dtsc = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services").fDenyTSConnections}
    else {$dtsc = "Key not Found"}
    $elua = 'HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\System'
    if (Test-Path $elua) {$elua = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\System").EnableLUA}
    else {$elua = "Key not Found"}
    $ddlun = 'HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\System'
    if (Test-Path $ddlun) {$ddlun = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\System").dontdisplaylastusername}
    else {$ddlun = "Key not Found"}
    
    #Services
    $ls = (Get-WmiObject Win32_Service -filter "Name='LanmanServer'").StartMode 
    $mpssvc = (Get-WmiObject Win32_Service -filter "Name='MPSSVC'").StartMode 
    $wd = (Get-WmiObject Win32_Service -filter "Name='WinDefend'").StartMode 
    $wscsvc = (Get-WmiObject Win32_Service -filter "Name='WSCSVC'").StartMode 
    $trkwks = (Get-WmiObject Win32_Service -filter "Name='TRKWKS'").StartMode 
    $napagent = (Get-WmiObject Win32_Service -filter "Name='NAPAGENT'").StartMode 
    $wuauserv = (Get-WmiObject Win32_Service -filter "Name='WUAUSERV'").StartMode 
    
    #Local Accounts
    $LCS = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True' AND Name='LCSAdmin'"
    $LCSAdmin = $LCS.Disabled
    $Gu = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True' AND Name='Guest'"
    $Guest = $Gu.Disabled
    
    #Make individual arrays from each queried information
    $RegValues = @($dnc,$acu,$he,$hscah,$ndtar,$tos,$ebt,$udnd,$dndl,$oads,$ads,$soc,$narwlou,$dc,$atgh,$dtsc,$elua,$ddlun)
    $ServiceValues = @($ls,$mpssvc,$wd,$wscsvc,$trkwks,$napagent,$wuauserv)
    $UsersValues = @($LCSAdmin,$Guest)
    
    #Make array of all keys
    $RegAll = @($RegKeys[0], $RegValues[0],$RegKeys[1], $RegValues[1],$RegKeys[2], $RegValues[2],$RegKeys[3], $RegValues[3], $RegKeys[4], $RegValues[4], $RegKeys[5], $RegValues[5]
    $RegKeys[6], $RegValues[6], $RegKeys[7], $RegValues[7], $RegKeys[8], $RegValues[8], $RegKeys[9], $RegValues[9], $RegKeys[10], $RegValues[10]
    $RegKeys[11], $RegValues[11], $RegKeys[12], $RegValues[12], $RegKeys[13], $RegValues[13], $RegKeys[14], $RegValues[14], $RegKeys[15], $RegValues[15]
    $RegKeys[16], $RegValues[16], $RegKeys[17], $RegValues[17], $RegKeys[18], $RegValues[18], $Services[0], $ServiceValues[0], $Services[1], $ServiceValues[1]
    , $Services[2], $ServiceValues[2], $Services[3], $ServiceValues[3], $Services[4], $ServiceValues[4], $Services[5], $ServiceValues[5], $Services[6], $ServiceValues[6],
    $Users[0], $UsersValues[0], $Users[1], $UsersValues[1])
    
    #output to html
    $RegAll | Select @{label='Item';expression={$_}} | ConvertTo-HTML -Fragment -Property 'Item' |Out-File c:\Scripts.html


    this one works to txt

    Code:
    write-output ("<<<<< Verifying Registry Settings >>>>>") |Out-File c:\Scripts.txt 
        $res = (Get-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Windows\Explorer").DisableNotificationCenter
        $reslcs = $res.DisableNotificationCenter
            if (!$reslcs) {$reslcs = "Key Not Found"}
        write-output ("DisableNotificationCenter = " + $reslcs) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings").AutoConfigURL
            if (!$res) {$res = "Key Not Found"}
        write-output ("AutoConfigURL = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power").HibernateEnabled
     #       if (!$res) {$res = "Key Not Found"}
        write-output ("HibernateEnabled = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer").HideSCAHealth
            if (!$res) {$res = "Key Not Found"}
        write-output ("HideSCAHealth = " + $res) |Out-File c:\Scripts.txt -Append
            $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer").NoDriveTypeAutoRun
            if (!$res) {$res = "Key Not Found"}
        write-output ("NoDriveTypeAutoRun = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Windows\Sidebar").TurnOffSidebar
            if (!$res) {$res = "Key Not Found"}
        write-output ("TurnOffSidebar = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\Explorer\Advanced").EnableBaloonTips
            if (!$res) {$res = "Key Not Found"}
        write-output ("EnableBaloonTips = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient").UseDomainNameDevolution
            if (!$res) {$res = "Key Not Found"}
        write-output ("UseDomainNameDevolution = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SYSTEM\CURRENTCONTROLSET\SERVICES\Dnscache\Parameters").DomainNameDevolutionlevel
            if (!$res) {$res = "Key Not Found"}
        write-output ("DomainNameDevolutionlevel = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\bms.com\*.one.ads")."*"
            if (!$res) {$res = "Key Not Found"}
        write-output ("bms.com\*.one.ads = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\bms.com")."*"
            if (!$res) {$res = "Key Not Found"}
        write-output ("bms.com = " + $res) |Out-File c:\Scripts.txt -Append
    
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching").SearchOrderConfig
    #        if (!$res) {$res = "Key Not Found"}
        write-output ("SearchOrderConfig = " + $res) |Out-File c:\Scripts.txt -Append
    
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU").NoAutoRebootWithLoggedOnUsers
            if (!$res) {$res = "Key Not Found"}
        write-output ("NoAutoRebootWithLoggedOnUsers = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters").DisabledComponents
            if (!$res) {$res = "Key Not Found"}
        write-output ("DisabledComponents = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Remote Assistance").fAllowToGetHelp
    #        if (!$res) {$res = "Key Not Found"}
        write-output ("fAllowToGetHelp = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services").fDenyTSConnections
            if (!$res) {$res = "Key Not Found"}
        write-output ("fDenyTSConnections = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\MICROSOFT\WINDOWS\CurrentVersion\Policies\System").EnableLUA
    #        if (!$res) {$res = "Key Not Found"}
        write-output ("EnableLUA = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System").dontdisplaylastusername
    #        if (!$res) {$res = "Key Not Found"}
        write-output ("dontdisplaylastusername = " + $res) |Out-File c:\Scripts.txt -Append
        write-output ("<<<<< /Verifying Registry Settings >>>>>") |Out-File c:\Scripts.txt -Append
        write-output (" ") |Out-File c:\Scripts.txt -Append
        write-output (" ") |Out-File c:\Scripts.txt -Append
    write-output ("<<<<< Verifying Services Settings >>>>>") |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='LanmanServer'").StartMode 
        write-output ("LanmanServer = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='MPSSVC'").StartMode 
        write-output ("MPSSVC = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='WinDefend'").StartMode 
        write-output ("WinDefend = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='WSCSVC'").StartMode 
        write-output ("WSCSVC = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='TRKWKS'").StartMode 
        write-output ("TRKWKS = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='NAPAGENT'").StartMode 
        write-output ("NAPAGENT = " + $res) |Out-File c:\Scripts.txt -Append
        $res = (Get-WmiObject Win32_Service -filter "Name='WUAUSERV'").StartMode 
        write-output ("WUAUSERV = " + $res) |Out-File c:\Scripts.txt -Append
    write-output ("<<<<< /Verifying Services Settings >>>>>") |Out-File c:\Scripts.txt -Append
        write-output (" ") |Out-File c:\Scripts.txt -Append
        write-output (" ") |Out-File c:\Scripts.txt -Append
    write-output ("<<<<< Verifying Account Settings >>>>>") |Out-File c:\Scripts.txt -Append
    $res = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True' AND Name='LCSAdmin'"
    $reslcs = $res.Disabled
    write-output ("LCSAdmin = " + $reslcs) |Out-File c:\Scripts.txt -Append
    $res = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True' AND Name='Guest'"
    $reslcs = $res.Disabled
    write-output ("Guest = " + $reslcs) |Out-File c:\Scripts.txt -Append
    write-output ("<<<<< /Verifying Account Settings >>>>>") |Out-File c:\Scripts.txt -Append
    HW - i5 4570T @2.9ghz runs @11w | 8gb ram | 128gb ssd OS - Win10 x64

    HS - HS3 Pro Edition 3.0.0.435

    Plugins - BLRF 2.0.94.0 | Concord 4 3.1.13.10 | HSBuddy 3.9.605.5 | HSTouch Server 3.0.0.68 | RFXCOM 30.0.0.36 | X10 3.0.0.36 | Z-Wave 3.0.1.190

    Hardware - EdgePort/4 DB9 Serial | RFXCOM 433MHz USB Transceiver | Superbus 2000 for Concord 4 | TI103 X-10 Interface | WGL Designs W800 RF | Z-Net Z-Wave Interface
Working...
X