Security Slideshow

  1. ####################### 
  2.  
  3. #Appscanner V0.10 
  4. #Author Adam Liquorish 
  5.  
  6. #Creation Date 08/11/11 
  7.  
  8. #Change log: 
  9.  
  10. #    14/11/11 Removed unrequired step 
  11.  
  12. #    02/12/11 Created input choice for domain.local,cached rather than auto determine 
  13.  
  14. #    02/12/11 Added all supported filetypes for applockers ".bat",".cmd",".dll",".exe",".js",".msi",".msp","ocx",".psq",".vbs" 
  15.  
  16. #    09/12/11 Implemented try/catch to capture file not found or access denied errors for outputting files 
  17.  
  18. # 
  19.  
  20. #Syntax 
  21.  
  22. #appscanner -path <path> -user <user> -applockerpolicy <local/path> -outputpath <path> -userstatus <domain,local,cached> -logdirectory <path> 
  23.  
  24. #     
  25.  
  26. #Example 
  27.  
  28. #appscanner -path "C:\Program Files" -user "adam" -applockerpolicy "local" -outputpath "c:\temp\output.html" -userstatus "local" -logdirectory "c:\temp\" 
  29.  
  30. ####################### 
  31.  
  32.    
  33.  
  34. ######Define Parameters 
  35.  
  36. param
  37.  
  38. [Parameter(Mandatory=$true
  39.  
  40.     HelpMessage="Enter Path to be processed.")] 
  41.  
  42.     [ValidateNotNullOrEmpty()] 
  43.  
  44.     [string]$path
  45.  
  46. [Parameter(Mandatory=$true
  47.  
  48.     HelpMessage="Enter User to be processed, as either builtin\<user> or <domain>\<user>.")] 
  49.  
  50.     [ValidateNotNullOrEmpty()] 
  51.  
  52.     [string]$user=$(Read-Host -prompt "User"), 
  53.  
  54. #Uncomment when in production version. 
  55.  
  56. [Parameter(Mandatory=$true
  57.  
  58.     HelpMessage="Enter Applocker XML to be utilised ie c:\applocker.xml, or type local to use effective policy for workstation")] 
  59.  
  60.     [ValidateNotNullOrEmpty()] 
  61.  
  62.     [string]$applockerpolicy=$(Read-Host -prompt "Path to applocker policy xml file, or type local to use effective policy for workstation"), 
  63.  
  64. [Parameter(Mandatory=$true
  65.  
  66.     HelpMessage="Enter Path for ouput ie c:\Temp\output.html.")] 
  67.  
  68.     [ValidateNotNullOrEmpty()] 
  69.  
  70.     [string]$outputpath=$(Read-Host -prompt "Path for Output"), 
  71.  
  72. [Parameter(Mandatory=$true
  73.  
  74.     HelpMessage="Is the user a Domain/Local/Cached User.[Domain,Local,Cached]")] 
  75.  
  76.     [ValidateNotNullOrEmpty()] 
  77.  
  78.     [ValidateSet("Domain","Local","Cached")] 
  79.  
  80.     [string]$UserStatus=$(Read-Host -prompt "Is the user a Domain/Local/Cached User.[Domain,Local,Cached]"), 
  81.  
  82. [Parameter(Mandatory=$true
  83.  
  84.     HelpMessage="Enter Log Directory for ouput ie c:\Temp\")] 
  85.  
  86.     [ValidateNotNullOrEmpty()] 
  87.  
  88.     [string]$logdirectory=$(Read-Host -prompt "Log Directory"
  89.  
  90.  
  91. ######END DEFINE PARAMETERS    
  92.  
  93. ######Define Logger 
  94.  
  95. $logfilename="$(get-date -format yyyy-MM-dd-hh-mm-ss).txt"  
  96.  
  97. $logfile=$logdirectory+$logfilename 
  98.  
  99. if ($host.name -match 'ise'
  100.  
  101.  
  102.     write-host "Warning: Running in Windows Powershell ISE, Transcript logging will not be running" -foregroundcolor red 
  103.  
  104.     $null 
  105.  
  106.  
  107. else 
  108.  
  109.  
  110.     write-host "Running in Powershell Console, Transcript logging will now start" -foregroundcolor blue 
  111.  
  112.     try{ 
  113.  
  114.         start-transcript -path $logfile 
  115.  
  116.     
  117.  
  118.     #catch for if path not found 
  119.  
  120.     catch [System.IO.DirectoryNotFoundException]{ 
  121.  
  122.         write-host "Critical: Parent Path to save $logfile not found." -foregroundcolor red 
  123.  
  124.         read-host "Press enter to exit" 
  125.  
  126.     
  127.  
  128.     #catch for path access denied 
  129.  
  130.     catch [System.Management.Automation.RuntimeException]{ 
  131.  
  132.         write-host "Critical: Write access to $logfile is denied unable to save log file." -foregroundcolor red 
  133.  
  134.         read-host "Press enter key to exit" 
  135.  
  136.     
  137.  
  138.  
  139. ###### END Logger 
  140.  
  141. ######Define Variables 
  142.  
  143. $ticksymbol=[char]10004 
  144.  
  145. $errorsymbol=[char]10008 
  146.  
  147. $asterisksymbol=[char]10033 
  148.  
  149. $dict=@{} 
  150.  
  151. $t=$null 
  152.  
  153. $hashtable=$null 
  154.  
  155. $u=$null 
  156.  
  157. $Pathvalid=test-path $path 
  158.  
  159. $Pathvalidpolicy=test-path $applockerpolicy 
  160.  
  161. $direct=$null 
  162.  
  163. $inherited=$null 
  164.  
  165.  
  166.  
  167. ######END DEFINE VARIABLEs 
  168.  
  169.  
  170.  
  171. ######Define HTML Output 
  172.  
  173. $a="<style>" 
  174.  
  175. $a=$a +"TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" 
  176.  
  177. $a=$a +"TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" 
  178.  
  179. $a=$a +"TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}" 
  180.  
  181. $a=$a +"</style>" 
  182.  
  183. $header= "<h1>List of Processed Files</h1>" 
  184.  
  185. ######END DEFINE HTML OUTPUT 
  186.  
  187. ######Testing Privileges 
  188.  
  189. #$currentprincipal=new-object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) 
  190.  
  191. #& { 
  192.  
  193. #    if ($currentprincipal.isinrole( [Security.principal.windowsbuiltinrole]::Administrator)) 
  194.  
  195. #    { 
  196.  
  197. #        write-host "$ticksymbol Running with administrative privilages" -foregroundcolor blue 
  198.  
  199. #    } 
  200.  
  201. #    else 
  202.  
  203. #    { 
  204.  
  205. #        write-host "$errorsymbol Script is currently not running with administrative privileges, please run as admin" -foregroundcolor red 
  206.  
  207. #        read-host "Press enter to exit" -foregroundcolor red 
  208.  
  209. #        exit 
  210.  
  211. #    } 
  212.  
  213. #  } 
  214.  
  215. ######END TESTING PRIV 
  216.  
  217. ######Importing Required Modules 
  218.  
  219. try 
  220.  
  221.  
  222.     if((get-wmiobject -cl win32_operatingsystem).version -gt "6"
  223.  
  224.     
  225.  
  226.         write-host "$ticksymbol Win Vista or higher detected, Importing Applocker Module" -foregroundcolor blue 
  227.  
  228.         if((get-module -listavailable|foreach-object {$_.name}) -contains "applocker"
  229.  
  230.         
  231.  
  232.             import-module applocker 
  233.  
  234.             write-host "Successfully imported applocker module" -foregroundcolor blue 
  235.  
  236.         
  237.  
  238.         else 
  239.  
  240.         
  241.  
  242.             write-host "Critical: Applocker module cannot be found try logging in as administrator" -foregroundcolor red 
  243.  
  244.             read-host "Press enter to quit" 
  245.  
  246.             exit 
  247.  
  248.         
  249.  
  250.     
  251.  
  252.     else 
  253.  
  254.     
  255.  
  256.         "Critical: $errorsymbol Exiting....An operating system lower that Windows Vista has been detected.  Script can only be run on Vista or higher." 
  257.  
  258.         read-host "Press Enter key to exit" 
  259.  
  260.         Exit 
  261.  
  262.     
  263.  
  264.  
  265. catch 
  266.  
  267.  
  268.     write-host "Critical: Error encountered loading applocker module" -foregroundcolor red 
  269.  
  270.     read-host "Press Enter key to exit" 
  271.  
  272.     Exit 
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279. ######END IMPORT MODULES 
  280.  
  281.  
  282.  
  283.  
  284.  
  285. ######MAIN 
  286.  
  287.  
  288.  
  289. if ($Pathvalid -eq "True"
  290.  
  291. #If Path Valid 
  292.  
  293.     
  294.  
  295.     if ($applockerpolicy -eq "local"
  296.  
  297.     #Output effective local applied applocker policy 
  298.  
  299.     
  300.  
  301.         #Determine whether an applocker policy is in effect on workstation 
  302.  
  303.         if((get-applockerpolicy -effective -xml ) -like "*Rule*"
  304.  
  305.         
  306.  
  307.             write-host "$ticksymbol A valid Applocker Policy is currently applied to this workstation" -foregroundcolor blue 
  308.  
  309.             write-host "Warning: A path is required to save local applied applocker policy for usage" -foregroundcolor red 
  310.  
  311.             $applockerpolicy=read-host "Enter path, ie c:\temp\applockerpolicy.xml"  
  312.  
  313.             write-host "$asterisksymbol Effective applied Applocker Policy for this workstation has been selected, policy will be output to $applockerpolicy" -foregroundcolor blue 
  314.  
  315.             #Effective Applocker policy output 
  316.  
  317.             try{ 
  318.  
  319.                 get-applockerpolicy -effective -xml >$applockerpolicy 
  320.  
  321.             
  322.  
  323.             #catch for if path not found 
  324.  
  325.             catch [System.IO.DirectoryNotFoundException]{ 
  326.  
  327.                 write-host "Critical: Parent Path to save $applockerpolicy not found." -foregroundcolor red 
  328.  
  329.                 read-host "Press enter to exit" 
  330.  
  331.             
  332.  
  333.             #catch for path access denied 
  334.  
  335.             catch [System.Management.Automation.RuntimeException]{ 
  336.  
  337.                 write-host "Critical: Write access to $applockerpolicy is denied unable to export policy." -foregroundcolor red 
  338.  
  339.                 read-host "Press enter key to exit" 
  340.  
  341.             
  342.  
  343.         
  344.  
  345.         else 
  346.  
  347.         
  348.  
  349.             write-host "Critical: $errorsymbol Exiting....An applocker policy has not been applied to this workstation" -foregroundcolor red 
  350.  
  351.             read-host "Press Enter key to exit" 
  352.  
  353.             exit 
  354.  
  355.         
  356.  
  357.          
  358.  
  359.     
  360.  
  361.     elseif ($Pathvalidpolicy -eq "True"
  362.  
  363.     
  364.  
  365.          write-host "$ticksymbol Valid XML file supplied for Applocker Policy" -foregroundcolor blue 
  366.  
  367.     
  368.  
  369.     else 
  370.  
  371.     
  372.  
  373.         write-host "Critical: $errorsymbol Exiting....Invalid path for applocker policy xml file, File Doesn't exist!" -foreground red 
  374.  
  375.         read-host "Press Enter key to exit" 
  376.  
  377.         exit 
  378.  
  379.     }   
  380.  
  381.     #Stage 1 Find group membership for user 
  382.  
  383.     $starttime=get-date 
  384.  
  385.     "Stage 1 of 7, Enumerating Groups User is a member of, including inherited groups" 
  386.  
  387.     #Load .Net Assembler 
  388.  
  389.     add-type -AssemblyName System.DirectoryServices.AccountManagement 
  390.  
  391.     $domain = (Get-wmiobject Win32_ComputerSystem).Domain 
  392.  
  393.     $ping=new-object system.net.networkinformation.ping 
  394.  
  395.      
  396.  
  397.     #Function for finding group membership for only local or domain not a cached user!!!  
  398.  
  399.     function groupfind   
  400.  
  401.     
  402.  
  403.         #Create objects to filter based on group name and ContextType--Domain or Machine 
  404.  
  405.         $principal = new-object System.DirectoryServices.AccountManagement.PrincipalContext $ctype,$domain 
  406.  
  407.         $idtype = [System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName 
  408.  
  409.         $groupPrincipal = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($principal, $idtype, $user
  410.  
  411.         #Recursively find what groups the user is a member of 
  412.  
  413.         #Also assigns groups found to a global variable called groupout 
  414.  
  415.         set-variable -name groupout -value $groupprincipal.GetAuthorizationGroups() -scope global 
  416.  
  417.     
  418.  
  419.     #END FUNCTION 
  420.  
  421.      
  422.  
  423.     #Determine if workstation is part of a domain or just local. 
  424.  
  425.     If($userstatus -eq "Domain"
  426.  
  427.     
  428.  
  429.         try { 
  430.  
  431.             $domainName = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain() | select -ExpandProperty Name 
  432.  
  433.             $isDomain = $domainName -match $domain 
  434.  
  435.             $domain =$domainname 
  436.  
  437.             write-host "Workstation is part of a domain" -foregroundcolor blue 
  438.  
  439.             #Determine if domain controller is contactable if not contactable treat workstation as local and use local account information 
  440.  
  441.             if ($ping.send(([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()).pdcroleowner.name).status -eq "Success"
  442.  
  443.             
  444.  
  445.                 $ctype = [System.DirectoryServices.AccountManagement.ContextType]::Domain 
  446.  
  447.                 write-host "Successfully contacted Domain controller, using Domain account information." -foregroundcolor blue 
  448.  
  449.                 #calls function groupfind 
  450.  
  451.                 groupfind 
  452.  
  453.             
  454.  
  455.             else 
  456.  
  457.             
  458.  
  459.                 write-host "Critical: Domain Controller not contactable!" -foregroundcolor red 
  460.  
  461.                 read-host "Press Enter key to exit" 
  462.  
  463.                 exit 
  464.  
  465.             
  466.  
  467.         
  468.  
  469.         catch { 
  470.  
  471.             write-host "Critical: Computer is not part of a domain" -foregroundcolor red 
  472.  
  473.             read-host "Press Enter key to exit" 
  474.  
  475.             exit 
  476.  
  477.         
  478.  
  479.     
  480.  
  481.     elseif($userstatus -eq "Local"
  482.  
  483.     
  484.  
  485.     #Build list of local users 
  486.  
  487.     $computername="$env:computername" 
  488.  
  489.     $computer=[ADSI]"WinNT://$computername,computer" 
  490.  
  491.     $localuserlist=$computer.psbase.children|where-object {$_.psbase.schemaclassname -eq 'user'
  492.  
  493.     $localuserlistfilt=foreach($useritem in $localuserlist){$useritem.name
  494.  
  495.         #Check queried user against list to see whether user is local 
  496.  
  497.         if($localuserlistfilt -contains $user
  498.  
  499.         
  500.  
  501.             write-host "Verified user is a part of local SAM database" -foregroundcolor blue 
  502.  
  503.             $domain=(Get-wmiobject Win32_ComputerSystem).Name 
  504.  
  505.             $ctype = [System.DirectoryServices.AccountManagement.ContextType]::Machine 
  506.  
  507.             #Calls function groupfind 
  508.  
  509.             groupfind 
  510.  
  511.         
  512.  
  513.         else 
  514.  
  515.         
  516.  
  517.             write-host "Critical: User is not a local user" -foregroundcolor red 
  518.  
  519.             read-host "Press Enter key to exit" 
  520.  
  521.             exit 
  522.  
  523.         
  524.  
  525.     
  526.  
  527.     elseif($userstatus -eq "Cached"
  528.  
  529.     
  530.  
  531.         try { 
  532.  
  533.         #Build list of local users 
  534.  
  535.         $computername="$env:computername" 
  536.  
  537.         $computer=[ADSI]"WinNT://$computername,computer" 
  538.  
  539.         $localuserlist=$computer.psbase.children|where-object {$_.psbase.schemaclassname -eq 'user'
  540.  
  541.         $localuserlistfilt=foreach($useritem in $localuserlist){$useritem.name
  542.  
  543.             #Check queried user against list to see whether user is local 
  544.  
  545.             if($localuserlistfilt -contains $user
  546.  
  547.             
  548.  
  549.                 write-host "Critical: User is a part of local SAM database, therefore user is not cached." -foregroundcolor red 
  550.  
  551.                 read-host "Press Enter key to exit" 
  552.  
  553.                 exit 
  554.  
  555.             
  556.  
  557.             else 
  558.  
  559.             
  560.  
  561.                 #Check queried user matches logged on user" 
  562.  
  563.                if((gwmi win32_computersystem).username -like "*$user"
  564.  
  565.                 
  566.  
  567.                     write-host "Verified user is a cached user" -foregroundcolor blue 
  568.  
  569.                     $groupout=[system.security.principal.windowsidentity]::getcurrent().groups|foreach-object {$_.translate([system.security.principal.ntaccount])} 
  570.  
  571.                 
  572.  
  573.                 else 
  574.  
  575.                 
  576.  
  577.                     write-host "Critical: Logged on user doesn't match queried user, therefore User is not a cached user" -foregroundcolor red 
  578.  
  579.                     read-host "Press Enter key to exit" 
  580.  
  581.                     exit 
  582.  
  583.                 
  584.  
  585.             }                     
  586.  
  587.         
  588.  
  589.         catch { 
  590.  
  591.             write-host "Critical: User is not cached" -foregroundcolor red 
  592.  
  593.             read-host "Press Enter key to exit" 
  594.  
  595.             exit 
  596.  
  597.         
  598.  
  599.     
  600.  
  601.     else 
  602.  
  603.     
  604.  
  605.         write-host "Critical: Please use Local,Domain or Cached" -foregroundcolor red 
  606.  
  607.         read-host "Press Enter key to exit" 
  608.  
  609.         exit 
  610.  
  611.     
  612.  
  613.      
  614.  
  615.  
  616.  
  617.      
  618.  
  619.     "Stage 1 of 7, Finished Scanning Group Membership" 
  620.  
  621.     "Stage 1 of 7, Outputting Group Membership hierarchy" 
  622.  
  623.     #Add user to variable 
  624.  
  625.     $groupfilter=@($user
  626.  
  627.     #Filter group properties down to name string 
  628.  
  629.     $groupfilter+=foreach($groupname in $groupout){$groupname.name
  630.  
  631.     #Determine direct membership 
  632.  
  633.     $domaincut=$domain -match "\w+[A-Za-z0-9-]+" 
  634.  
  635.     $domaincutvalue=$matches.values 
  636.  
  637.     $query="ASSOCIATORS OF {Win32_Account.Name='$user',Domain='$domaincutvalue'} WHERE ResultRole=GroupComponent ResultClass=Win32_Account" 
  638.  
  639.     $directmembership=get-wmiobject -query $query 
  640.  
  641.     $directmembershipresults=foreach($directmember in $directmembership){$directmember.name
  642.  
  643.     $directmembershipresultsfiltered=$directmembershipresults|select-object -unique 
  644.  
  645.      
  646.  
  647.     "#####################################################" 
  648.  
  649.     write-host "#Green is for the username," -foregroundcolor darkgreen -nonewline; write-host "Red is for direct group membership," -foregroundcolor red -nonewline; write-host "Blue is for the inherited group membership" -foregroundcolor blue 
  650.  
  651.     "#User $user group structure looks like the following;" 
  652.  
  653.     foreach ($group in $groupfilter){ 
  654.  
  655.         if($directmembershipresultsfiltered -contains $group){ 
  656.  
  657.             $direct+=@($group)} 
  658.  
  659.         elseif($group -eq $user){ 
  660.  
  661.             $null
  662.  
  663.         else{$inherited+=@($group)} 
  664.  
  665.       
  666.  
  667.     #Display user 
  668.  
  669.     write-host "-$user" -foregroundcolor darkgreen 
  670.  
  671.     #Display direct membership 
  672.  
  673.     foreach($member in $direct){ 
  674.  
  675.         write-host "->$member" -foregroundcolor red 
  676.  
  677.         
  678.  
  679.     foreach($member in $inherited){ 
  680.  
  681.         write-host "-->$member" -foregroundcolor blue 
  682.  
  683.         
  684.  
  685.     "#####################################################" 
  686.  
  687.     "Stage 1 of 7 Complete" 
  688.  
  689.     #End Stage 1 
  690.  
  691.      
  692.  
  693.     #Stage 2 Recurse found items to variable 
  694.  
  695.     $count=
  696.  
  697.     "Stage 2 of 7 $path is populating a variable " 
  698.  
  699.     Get-Childitem $path -recurse -outvariable objects|where-object{write-progress "Stage 2 of 7 Recursing items to variable, Examining $($_.fullname)...." "Found  $count items";"$($_.fullname)"}|foreach-object {$count++
  700.  
  701.     "Stage 2 of 7 $path has been populated into a variable" 
  702.  
  703.     #End Stage 2 
  704.  
  705.      
  706.  
  707.     #Stage 3 FILTERACL 
  708.  
  709.     "Stage 3 of 7 Processing ACL on files to index" 
  710.  
  711.      $max=$objects.length 
  712.  
  713.      #filter variable 
  714.  
  715.      $filteracl ={$groupfilter -like $_.IdentityReference.value.split("\")[1] -and ($_.FileSystemRights -band 131241 -or $_.FileSystemRights -band 278)} 
  716.  
  717.      #Filter and add to new property 
  718.  
  719.      foreach ($i in $objects
  720.  
  721.        
  722.  
  723.             $dict[$i.fullname]=@{user="";Permission=""}  
  724.  
  725.             $t++ 
  726.  
  727.             $i.GetAccessControl().Access |Where $filteracl|foreach {$dict.($i.Fullname).User+=($_.IdentityReference,",");$dict.($i.Fullname).Permission=$_.FileSystemRights}  
  728.  
  729.             Write-Progress -activity "Stage 3 of 7 Processing File Permissions to index" -status "$t of $max" -PercentComplete (($t/$objects.count)*100) -CurrentOperation $i.fullname  
  730.  
  731.        
  732.  
  733.      
  734.  
  735.     "Stage 3 of 7 Complete" 
  736.  
  737.     #END STAGE 3 
  738.  
  739.      
  740.  
  741.     #Stage 4 Remove Duplicate identities 
  742.  
  743.     "Stage 4 of 7 Removing duplicate identities" 
  744.  
  745.     #Zeroise write-progress counter 
  746.  
  747.     $t=$null 
  748.  
  749.     #Remove duplicate identities due to listing of inherited groups in ACL 
  750.  
  751.       foreach ($i in $objects
  752.  
  753.     
  754.  
  755.         $t++ 
  756.  
  757.         $identarray=$dict[$i.fullname].user;$dict[$i.fullname].user=$null;$splitidentarray=$identarray -split ",";$uniqueidentarray=$splitidentarray|sort-object -unique;$uniqueidentarray -join ","|foreach {$dict.($i.fullname).User+=($_)} 
  758.  
  759.         Write-Progress -activity "Stage 4 of 7 Removing Username/Group Duplicates" -status "$t of $max" -PercentComplete (($t/$objects.count)*100) -CurrentOperation $i.fullname  
  760.  
  761.     
  762.  
  763.     "Stage 4 of 7 Complete" 
  764.  
  765.     #END STAGE 4 
  766.  
  767.  
  768.  
  769.     #Stage 5 APPLOCKER 
  770.  
  771.     "Stage 5 of 7 Processing Applocker policy on files" 
  772.  
  773.     #Applocker file extensions list 
  774.  
  775.     $Applockerfileextlist=".bat",".cmd",".dll",".exe",".js",".msi",".msp","ocx",".psq",".vbs" 
  776.  
  777.     $userpol=$objects|where {$Applockerfileextlist -contains $_.Extension}|convert-path|test-applockerpolicy $applockerpolicy -User $user 
  778.  
  779.     $userobjpol = $userpol|select-object PolicyDecision,FilePath,MatchingRule 
  780.  
  781.     $userobjpolcount=
  782.  
  783.     $userobjpol|foreach
  784.  
  785.         $userobjpolcount++ 
  786.  
  787.         $dict[$_.FilePath] += @{ PolicyDecision = $_.PolicyDecision;MatchingRule= $_.MatchingRule
  788.  
  789.         Write-progress -activity "Stage 5 of 7 Processing AppLockers results:" -status "$userobjpolcount of $($userobjpol.count)" -PercentComplete (($userobjpolcount/$userobjpol.count)*100) -CurrentOperation $_ 
  790.  
  791.     
  792.  
  793.     "Stage 5 of 7 Complete" 
  794.  
  795.     #END STAGE 5 
  796.  
  797.  
  798.  
  799.     #Stage 6 
  800.  
  801.     "Stage 6 0f 7 Preparing format of results for html Report" 
  802.  
  803.     $max2=$dict.count 
  804.  
  805.     $hashtable=foreach($j in $dict.keys){ 
  806.  
  807.         $u++ 
  808.  
  809.         New-Object -TypeName PSObject -Property @{Path=$j 
  810.  
  811.         User=$dict.$j.user 
  812.  
  813.         Permission=$dict.$j.Permission 
  814.  
  815.         MatchingRule=$dict.$j.MatchingRule 
  816.  
  817.         PolicyDecision=$dict.$j.PolicyDecision 
  818.  
  819.     
  820.  
  821.     Write-Progress -activity "Stage 6 of 7 Processing Dictionary to properties" -status "$u of $max2" -PercentComplete (($u/$max2)*100) -CurrentOperation $_
  822.  
  823.     "Stage 6 of 7 Complete, $u files scanned of $max for Applocker scan" 
  824.  
  825.     #END STAGE 6 
  826.  
  827.     #####END MAIN  
  828.  
  829.     #####RESULTS 
  830.  
  831.     #OUTPUT RESULTS TO FILE 
  832.  
  833.     "Stage 7 of 7 Outputting to file $outputpath" 
  834.  
  835.     try{ 
  836.  
  837.         $hashtable|sort-object Path|ConvertTo-Html -head $header -title "ACL List" -body $a|Set-Content $outputpath 
  838.  
  839.     
  840.  
  841.     #catch for if path not found 
  842.  
  843.     catch [System.IO.DirectoryNotFoundException]{ 
  844.  
  845.         write-host "Critical: Parent Path to save $outputpath not found." -foregroundcolor red 
  846.  
  847.         read-host "Press enter to exit" 
  848.  
  849.     
  850.  
  851.     #catch for path access denied 
  852.  
  853.     catch [System.Management.Automation.RuntimeException]{ 
  854.  
  855.         write-host "Critical: Write access to $outputpath is denied unable to export results." -foregroundcolor red 
  856.  
  857.         read-host "Press enter key to exit" 
  858.  
  859.     
  860.  
  861.     #Display results 
  862.  
  863.     $endtime=get-date 
  864.  
  865.     $totaltime=$endtime-$starttime 
  866.  
  867.     $totaltimehours=$totaltime.hours 
  868.  
  869.     $totaltimeminutes=$totaltime.minutes 
  870.  
  871.     $outputsize=get-item "$outputpath"|foreach {echo($_.length/1mb).tostring("0.00 MB")} 
  872.  
  873.     "Stage 7 of 7, Scanned $max files of $path is complete in $totaltimehours hours and $totaltimeminutes minutes, $outputpath is $outputsize." 
  874.  
  875.     #####END RESULTS 
  876.  
  877.     #####Zeroise variables and unrequired files 
  878.  
  879.     #Stop Logging 
  880.  
  881.     if ($host.name -match 'ise'
  882.  
  883.     
  884.  
  885.         $null 
  886.  
  887.     
  888.  
  889.     else 
  890.  
  891.     
  892.  
  893.         "Running Log output to $logfile" 
  894.  
  895.         stop-transcript >$null 
  896.  
  897.     
  898.  
  899.     #Prompt delete applocker policy 
  900.  
  901.     $delete=read-host -prompt "Would you like the Applocker policy file $applockerpolicy deleted,YES/NO" 
  902.  
  903.     if($delete -eq "yes"
  904.  
  905.     
  906.  
  907.         del $applockerpolicy 
  908.  
  909.     
  910.  
  911.     else 
  912.  
  913.     
  914.  
  915.         write-host "Warning: $asterisksymbol You chose not to delete file $applockerpolicy, Application will now exit....." -foregroundcolor red 
  916.  
  917.         read-host "Press Enter key to exit" 
  918.  
  919.     
  920.  
  921.  
  922.      
  923.  
  924. #If Path invalid 
  925.  
  926. else 
  927.  
  928.  
  929.     write-host "Critical: $errorsymbol Exiting...Invalid path supplied for processing" -foregroundcolor red 
  930.  
  931.     read-host "Press Enter key to exit" 
  932.  
  933.     exit 
  934.  
 
Loading...
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.