PoshCode Archive  Artifact [f99521eb0d]

Artifact f99521eb0dad7acec52c609243acc99bfe3f7c586ce785c5b2c33d54e6eb2280:

  • File Set-AssemblyBindLogging.ps1 — part of check-in [7c73ef1215] at 2018-06-10 13:03:32 on branch trunk — Enable or disable assembly bind logging (per-machine) (user: unknown size: 1897)

# encoding: ascii
# api: powershell
# title: Set-AssemblyBindLogging
# description: Enable or disable assembly bind logging (per-machine)
# version: 0.1
# type: function
# license: CC0
# function: Set-AssemblyBindLogging
# x-poshcode-id: 1976
# x-archived: 2010-07-18T09:01:24
#
#
function Set-AssemblyBindLogging {
#.Synopsis
#  Enable or disable Assembly Bind logging for the machine
#.Parameter EnableLogging
#  Whether or not to enable logging. Accepts partial matching of Enable/Disable or True/False or even 1/0 ... 
#.Parameter LogPath
#  The location of the folder you want to save fusion logs to. Will be created if it does not already exist
#  NOTE: If you are DISABLING logging, this folder will be DELETED (if it is empty).
[CmdletBinding()]
   param( 
      [Parameter(Mandatory=$true)]
      #[ValidateSet("Enable","Disable","True","False","0","1")]
      [string]$EnableLogging
   ,
      $LogPath = "C:\Logs\Fusion" 
   )

   foreach($RegistryRoot in "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion","HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Fusion") {
      switch -regex ($EnableLogging) {
         "En?a?b?l?e?|Tr?u?e?|1" {
            mkdir $LogPath -Force -EA Stop

            Set-ItemProperty REGISTRY::$RegistryRoot LogPath $LogPath
            foreach($switch in "LogFailures","ForceLog","LogResourceBinds") {
               Set-ItemProperty REGISTRY::$RegistryRoot $switch 1 -Type DWord
            }
         }
         "Di?s?a?b?l?e?|Fa?l?s?e?|0" {
            rmdir $LogPath
            foreach($switch in "LogPath","LogFailures","ForceLog","LogResourceBinds") {
               Remove-ItemProperty $switch
            }
         }
         default {
            throw "Couldn't convert '$EnableLogging' to a valid value. Valid values are: Enable or Disable, True or False, 1 or 0."
         }
      }
   }  
}