$message = "Do you want to set AppLocker default rules?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
  "Sets AppLocker default rules."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
  "Does nothing."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
switch ($result) {
  0 {
    $dir = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
    $e = (Get-ItemProperty $dir -Name EditionID).EditionID
    if ($e -eq 'Enterprise' -or $e -eq 'EnterpriseEval') {
      Import-Module AppLocker
      $i = Get-AppLockerFileInformation -Directory 'C:\Program Files\' -Recurse -FileType Dll, Exe, Script
      $p = $i | New-AppLockerPolicy -IgnoreMissingFileInformation -Optimize -RuleType Path -User Everyone -RuleNamePrefix Everyone_Dll_Exe_Script_Path_Program_Files
      $p | Set-AppLockerPolicy

      if ([System.IntPtr]::Size -eq 8) {
        $i = Get-AppLockerFileInformation -Directory 'C:\Program Files (x86)\' -Recurse -FileType Dll, Exe, Script
        $p = $i | New-AppLockerPolicy -IgnoreMissingFileInformation -Optimize -RuleType Path -User Everyone -RuleNamePrefix Everyone_Dll_Exe_Script_Path_Program_Files_(x86)
        $p | Set-AppLockerPolicy -Merge
      }
      $i = Get-AppLockerFileInformation -Directory C:\Windows\ -Recurse -FileType Dll, Exe, Script
      $p = $i | New-AppLockerPolicy -IgnoreMissingFileInformation -Optimize -RuleType Path -User Everyone -RuleNamePrefix Everyone_Dll_Exe_Script_Path_Windows
      $p | Set-AppLockerPolicy -Merge
      $i = Get-AppLockerFileInformation -Directory C:\ -Recurse -FileType Dll, Exe, Script, WindowsInstaller
      $p = $i | New-AppLockerPolicy -IgnoreMissingFileInformation -Optimize -RuleType Path -User Administrators -RuleNamePrefix Administrators_All
      $p | Set-AppLockerPolicy -Merge
      $i = Get-AppLockerFileInformation -Directory C:\ -Recurse -FileType Appx, WindowsInstaller
      $p = $i | New-AppLockerPolicy -IgnoreMissingFileInformation -Optimize -RuleType Publisher -User Everyone -RuleNamePrefix Everyone_Appx_WindowsInstaller_Publisher
      $p | Set-AppLockerPolicy -Merge
      $i = Get-AppLockerFileInformation -Directory C:\Windows\Installer\ -Recurse -FileType WindowsInstaller
      $p = $i | New-AppLockerPolicy -IgnoreMissingFileInformation -Optimize -RuleType Path -User Everyone -RuleNamePrefix Everyone_WindowsInstaller_Path_Windows\Installer
      $p | Set-AppLockerPolicy -Merge
    } else {
      'AppLocker is not available on Windows 8.1 ' + $e + '.'
    }
  }
}
