gangstanthony

Get-IEZone.ps1

Feb 25th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://www.reddit.com/r/PowerShell/comments/47lvkb/function_getiezone_gets_activex_settings_and_more/
  2.  
  3. function Get-IEZone-setlookup ($keything) {
  4.     # 1A00 Excluded
  5.     $KeyArray = '1001','1004','1200','1201','1206','1208','1209','1400','1402','1405','1605','1609','1803','1809','2000','2200','2201','2700','270C'
  6.     if ($KeyArray -contains $Keything) {
  7.         switch ($Keything) {
  8.             '1001' {[pscustomobject][ordered]@{
  9.                 Category    = 'ActiveX'
  10.                 Description = 'Download signed ActiveX controls'
  11.             }}# ACTX:Download signed ActiveX controls
  12.             '1004' {[pscustomobject][ordered]@{
  13.                 Category    = 'ActiveX'
  14.                 Description = 'Download unsigned ActiveX controls'
  15.             }}# ACTX:Download unsigned ActiveX controls
  16.             '1200' {[pscustomobject][ordered]@{
  17.                 Category    = 'ActiveX'
  18.                 Description = 'Run ActiveX controls and plug-ins'
  19.             }}# ACTX:Run ActiveX controls and plug-ins
  20.             '1201' {[pscustomobject][ordered]@{
  21.                 Category    = 'ActiveX'
  22.                 Description = 'Initialize and script ActiveX controls not marked as safe for scripting'
  23.             }}# A CTX:Initialize and script ActiveX controls not marked as safe for scripting
  24.             '1206' {[pscustomobject][ordered]@{
  25.                 Category    = 'Miscellaneous'
  26.                 Description = 'Allow scripting of Internet Explorer Web browser control'
  27.             }}# MISC:Allow scripting of Internet Explorer Web browser control ^
  28.             '1208' {[pscustomobject][ordered]@{
  29.                 Category    = 'ActiveX'
  30.                 Description = 'Allow previously unused ActiveX controls to run without prompt'
  31.             }}# ACTX:Allow previously unused ActiveX controls to run without prompt ^
  32.             '1209' {[pscustomobject][ordered]@{
  33.                 Category    = 'ActiveX'
  34.                 Description = 'Allow Scriptlets'
  35.             }}# ACTX:Allow Scriptlets
  36.             '1400' {[pscustomobject][ordered]@{
  37.                 Category    = 'Scripting'
  38.                 Description = 'Active scripting'
  39.             }}# SRPT:Active Scripting
  40.             '1402' {[pscustomobject][ordered]@{
  41.                 Category    = 'Scripting'
  42.                 Description = 'Scripting of Java applets'
  43.             }}# SRPT:Scripting of Java applets
  44.             '1405' {[pscustomobject][ordered]@{
  45.                 Category    = 'ActiveX'
  46.                 Description = 'Script ActiveX controls marked as safe for scripting'
  47.             }}# ACTX:Script ActiveX controls marked as safe for scripting
  48.             '1605' {[pscustomobject][ordered]@{
  49.                 Category    = 'Admin'
  50.                 Description = 'Run Java'
  51.             }}# ADMN:Run Java #
  52.             '1609' {[pscustomobject][ordered]@{
  53.                 Category    = 'Miscellaneous'
  54.                 Description = 'Display mixed content'
  55.             }}# MISC:Display mixed content *
  56.             '1803' {[pscustomobject][ordered]@{
  57.                 Category    = 'Downloads'
  58.                 Description = 'File Download'
  59.             }}# DOWN:File downloads ^
  60.             '1809' {[pscustomobject][ordered]@{
  61.                 Category    = 'Miscellaneous'
  62.                 Description = 'Use Pop-up Blocker'
  63.             }}# MISC:Use Pop-up Blocker ** ^
  64.             '1A00' {[pscustomobject][ordered]@{
  65.                 Category    = 'Authentication'
  66.                 Description = 'Logon'
  67.             }}# USER:Logon
  68.             '2000' {[pscustomobject][ordered]@{
  69.                 Category    = 'ActiveX'
  70.                 Description = 'Binary and script behaviors'
  71.             }}# ACTX:Binary and script behaviors
  72.             '2200' {[pscustomobject][ordered]@{
  73.                 Category    = 'Downloads'
  74.                 Description = 'Automatic prompting for file downloads'
  75.             }}# DOWN:Automatic prompting for file downloads ** ^
  76.             '2201' {[pscustomobject][ordered]@{
  77.                 Category    = 'ActiveX'
  78.                 Description = 'Automatic prompting for ActiveX controls'
  79.             }}# ACTX:Automatic prompting for ActiveX controls ** ^
  80.             '2702' {[pscustomobject][ordered]@{
  81.                 Category    = 'ActiveX'
  82.                 Description = 'Allow ActiveX Filtering'
  83.             }}# ACTX:Allow ActiveX Filtering
  84.             '270C' {[pscustomobject][ordered]@{
  85.                 Category    = 'ActiveX'
  86.                 Description = 'Run Antimalware software on ActiveX controls'
  87.             }}# ACTX:Run Antimalware software on ActiveX controls
  88.             default { $null }
  89.         }
  90.     }
  91.     #    *  indicates an Internet Explorer 6 or later setting
  92.     #    ** indicates a Windows XP Service Pack 2 or later setting
  93.     #    #  indicates a setting that is not displayed in the user interface in Internet Explorer
  94.     #    ^  indicates a setting that only has two options, enabled or disabled
  95. }
  96.  
  97. function Get-IEZone {
  98. [cmdletbinding(defaultparametersetname = 'Level_HKCU')]
  99.     param(
  100.     [Parameter(ParameterSetName = 'Level_HKLM',
  101.             Mandatory = $true,
  102.             Position = 0)]
  103.     [Parameter(ParameterSetName = 'Level_HKU',
  104.             Mandatory = $true,
  105.             Position = 0)]
  106.     [Parameter(ParameterSetName = 'Level_HKCU',
  107.             Mandatory = $true,
  108.             Position = 0)]
  109.     [ValidateSet('Internet', 'Intranet', 'Trusted', 'Restricted')]
  110.     [string]$Zone,
  111.  
  112.     [Parameter(ParameterSetName = 'Level_HKLM',
  113.             Mandatory = $false,
  114.             Position = 1)]
  115.     [switch]$LocalMachine,
  116.  
  117.     [Parameter(ParameterSetName = 'Level_HKCU',
  118.             Mandatory = $false,
  119.             Position = 1)]
  120.     [switch]$CurrentUser,
  121.  
  122.     [Parameter(ParameterSetName = 'Level_HKU',
  123.             Mandatory = $false,
  124.             Position = 1)]
  125.     [string[]]$User)
  126.    
  127.     begin {
  128.         $dWordNAME = $dWordVALUE = $requesttxt = $openZone = $ZoneSetsRAW = $null
  129.         $userpath = $userRAW = $userfound = $UserSID = $null
  130.         $regex1 = [regex]'[0-Z]{4}'
  131.         $ZoneID = $null
  132.         $settingsOUT = New-Object System.Collections.ArrayList
  133.    
  134.         switch ($zone) {
  135.             'Internet'  {$ZoneID = 3}
  136.             'Intranet'  {$zoneID = 1}
  137.             'Trusted'   {$ZoneID = 2}
  138.             'Restricted'{$ZoneID = 4}
  139.         }
  140.  
  141.         $set = $PSCmdlet.ParameterSetName
  142.         switch ($set) {
  143.             'Level_HKLM' {$openBase_HKLM = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::default)}
  144.             'Level_HKCU' {$openBase_HKCU = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::CurrentUser, [Microsoft.Win32.RegistryView]::default)}
  145.             'Level_HKU'  {$openBase_HKU  = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::Users, [Microsoft.Win32.RegistryView]::default)}
  146.         }
  147.     }
  148.  
  149.     process {
  150.         switch ($set) {
  151.             'Level_HKLM' {
  152.                 $ZoneSetsRAW = New-Object System.Collections.ArrayList
  153.                 $requesttxt = "`
  154.                Zone: $zone | LOCAL MACHINE"
  155.                 $openZone = $openBase_HKLM.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\$ZONEID")
  156.                 foreach ($dWordNAME in $openZone.GetValueNames()) {
  157.                     if ($dWordName -match $regex1) {
  158.                         $dWordVALUE = $openZone.GetValue($dWordNAME)
  159.                         $ZoneSetsRAW.Add([pscustomobject][ordered]@{
  160.                             Name  = $dWordNAME
  161.                             Value = $dWordVALUE
  162.                         }) | Out-Null
  163.                     }
  164.                 }
  165.                 foreach ($rec in $ZoneSetsRAW) {
  166.                     if ($rec.name -match $regex1) {
  167.                         $SetDESC = Get-IEZone-setlookup $rec.name
  168.                         $TranslatedValue = $(switch ($rec.value) {
  169.                             0 {'Enabled'}
  170.                             1 {'Prompt'}
  171.                             3 {'Disabled'}
  172.                         })
  173.                         if ($SetDESC -ne $null) {
  174.                             $settingsOUT.Add([pscustomobject][ordered]@{
  175.                                 Zone        = $Zone
  176.                                 User        = 'LOCAL MACHINE'
  177.                                 Category    = $SetDESC.category
  178.                                 Value       = $TranslatedValue
  179.                                 Description = $SetDESC.Description
  180.                             }) | Out-Null
  181.                         }
  182.                     }
  183.                 }
  184.             }
  185.  
  186.             'Level_HKCU' {
  187.                 $ZoneSetsRAW = New-Object System.Collections.ArrayList
  188.                 $requesttxt = "`
  189.                Zone: $zone | Current User: $env:username"
  190.                 $openZone = $openBase_HKCU.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\$ZONEID")
  191.                 foreach ($dWordNAME in $openZone.GetValueNames()) {
  192.                     if ($dWordName -match $regex1) {
  193.                         $dWordVALUE = $openZone.GetValue($dWordNAME)
  194.                         $ZoneSetsRAW.Add([pscustomobject][ordered]@{
  195.                             Name  = $dWordNAME
  196.                             Value = $dWordVALUE
  197.                         }) | Out-Null
  198.                     }
  199.                 }
  200.                 foreach ($rec in $ZoneSetsRAW) {
  201.                     if ($rec.name -match $regex1) {
  202.                         $SetDESC = Get-IEZone-setlookup $rec.name
  203.                         $settings = $null
  204.                         $TranslatedValue = $(switch ($rec.value) {
  205.                             0 {'Enabled'}
  206.                             1 {'Prompt'}
  207.                             3 {'Disabled'}
  208.                         })
  209.                         if ($SetDESC -ne $null) {
  210.                             $settingsOUT.Add([pscustomobject][ordered]@{
  211.                                 Zone        = $Zone
  212.                                 User        = $env:username
  213.                                 Category    = $SetDESC.category
  214.                                 Value       = $TranslatedValue
  215.                                 Description = $SetDESC.Description
  216.                             }) | Out-Null
  217.                         }
  218.                     }
  219.                 }
  220.             }
  221.  
  222.             'Level_HKU' {
  223.                 $userpath = $null
  224.                 $requesttxt = "`              
  225.                Zone: $Zone | User: $USER"
  226.                 $UserNameList = New-Object System.Collections.ArrayList
  227.                 foreach ($subkey in $openBase_HKLM.OpenSubKey('Software\\Microsoft\\Windows NT\\CurrentVersion\\profilelist').GetSubkeyNames()) {
  228.                     $userpath = $openBase_HKLM.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\profilelist\\$subkey").GetValue('ProfileImagePath')
  229.                     if ($userpath -notlike ('C:\Windows*')) {
  230.                         $userRAW = $userpath -split ('\\')
  231.                         $userfound = $userRAW[2]
  232.                         $UserNameList.Add([pscustomobject][ordered]@{
  233.                             Username = $userfound
  234.                             SID      = $subkey
  235.                         }) | Out-Null
  236.                     }
  237.                 }
  238.                 if ($usernamelist.Username -eq $USER) {
  239.                     $UserSID = $usernamelist | Where {$_.Username -eq $user} | Select -ExpandProperty SID
  240.                     $ZoneSetsRAW = New-Object System.Collections.ArrayList
  241.                     $openZone = $openBase_HKU.OpenSubKey("$UserSID\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\$ZONEID")
  242.                     try {
  243.                         foreach ($dWordNAME in $openZone.GetValueNames()) {
  244.                             if ($dWordName -match $regex1) {
  245.                                 $dWordVALUE = $openZone.GetValue($dWordNAME)
  246.                                 $ZoneSetsRAW.Add([pscustomobject][ordered]@{
  247.                                     Name  = $dWordNAME
  248.                                     Value = $dWordVALUE
  249.                                 }) | Out-Null
  250.                             }
  251.                         }
  252.                     } catch {
  253.                         Write-Warning "User SID not found in REG lookup"
  254.                     }
  255.                     foreach ($rec in $ZoneSetsRAW) {
  256.                         $settings = $SetDESC = $null
  257.                         if ($rec.name -match $regex1) {
  258.                             $SetDESC = Get-IEZone-setlookup $rec.name
  259.                             $TranslatedValue = $(switch ($rec.value) {
  260.                                 0 {'Enabled'}
  261.                                 1 {'Prompt'}
  262.                                 3 {'Disabled'}
  263.                             })
  264.                             if ($SetDESC -ne $null) {
  265.                                 $settingsOUT.Add([pscustomobject][ordered]@{
  266.                                     Zone        = $Zone
  267.                                     User        = $User
  268.                                     Category    = $SetDESC.category
  269.                                     Value       = $TranslatedValue
  270.                                     Description = $SetDESC.Description
  271.                                 }) | Out-Null
  272.                             }
  273.                         }
  274.                     }
  275.                 } else {
  276.                     Write-Warning 'User Not Found'
  277.                 }
  278.             }
  279.         }
  280.     }
  281.  
  282.     end {
  283.         #Write-Host $requesttxt -ForegroundColor Cyan
  284.         Write-Output $settingsOUT | sort -Property Category, Value
  285.     }
  286. }
Add Comment
Please, Sign In to add comment