Sunday, 22 February 2009

Get-MachineConfig

  1. <# 
  2. .SYNOPSIS 
  3.     Displays summary of machine.config 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample which fetchs the machine.config 
  6.     file, prints out file path, and key sections. Also shows how many sections 
  7.     exist in the machine.config file. Also fixed errors in original C# code 
  8.     and improved the layout of the results a bit. 
  9. .NOTES 
  10.     File Name  : get-machineconfig.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     Updated Powershell script posted to: 
  15.     http://pshscripts.blogspot.com/2009/02/get-machineconfig.html
  16.     MSDN Sample at: 
  17.     http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmachineconfiguration(VS.80).aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .\get-machinefoncif.ps1 
  20.     File path: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config 
  21.      
  22.        Name                                Allow Definition 
  23.        ----                                ---------------- 
  24.     system.data                        MachineToApplication 
  25.     windows                            MachineToApplication 
  26.     system.webServer                   MachineToApplication 
  27.     mscorlib                           MachineToApplication 
  28.     system.data.oledb                  MachineToApplication 
  29.     system.data.oracleclient           MachineToApplication 
  30.     system.data.sqlclient              MachineToApplication 
  31.     configProtectedData                MachineToApplication 
  32.     satelliteassemblies                MachineToApplication 
  33.     system.data.dataset                MachineToApplication 
  34.     startup                            MachineToApplication 
  35.     system.data.odbc                   MachineToApplication 
  36.     system.diagnostics                 MachineToApplication 
  37.     runtime                            MachineToApplication 
  38.     system.codedom                     MachineToApplication 
  39.     system.runtime.remoting            MachineToApplication 
  40.     connectionStrings                  MachineToApplication 
  41.     assemblyBinding                    MachineToApplication 
  42.     appSettings                        MachineToApplication 
  43.     system.windows.forms               MachineToApplication 
  44.     Total number of sections: 20 
  45. #> 
  46.  
  47. ### 
  48. #  Start of Script 
  49. # Get the machine.config file. 
  50. #### 
  51.  
  52. # Get config file 
  53. $config = [System.Configuration.ConfigurationManager]::OpenMachineConfiguration() 
  54.  
  55. #Display machine.config path. 
  56. "";"File path: {0}" -f $config.FilePath; "" 
  57.  
  58. # Loop to get the sections and display basic information. 
  59. "{0,-25}     {1,25}"  -f "   Name", "   Allow Definition" 
  60. "{0,-25}     {1,25}"  -f "   ----", "   ----------------" 
  61. $i = 0 
  62. foreach ($section in $config.Sections)  { 
  63. "{0,-25}     {1,25}" -f $section.SectionInformation.Name,$section.SectionInformation.AllowExeDefinition 
  64. $i++ 
  65. # Display total sections     
  66. "Total number of sections: {0}" -f $i  

No comments: