Advertisement
hooge

Get-RegistrySize

Apr 5th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #requires -version 2.0
  2.  
  3. # -----------------------------------------------------------------------------
  4. # Script: get-registry.ps1
  5. # Version: 1.0
  6. # Author: Jeffery Hicks
  7. # http://jdhitsolutions.com/blog
  8. # http://twitter.com/JeffHicks
  9. # http://www.ScriptingGeek.com
  10. # Date: 5/4/2011
  11. # Keywords: Registry, WMI
  12. # Comments:
  13. #
  14. # "Those who forget to script are doomed to repeat their work."
  15. #
  16. # ****************************************************************
  17. # * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
  18. # * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF *
  19. # * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
  20. # * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. *
  21. # ****************************************************************
  22. # -----------------------------------------------------------------------------
  23.  
  24. Function Get-Registry {
  25.  
  26. <#
  27. .SYNOPSIS
  28. Get registry size and utilization
  29. .DESCRIPTION
  30. This command uses WMI to retrieve size and status information for the Windows registry. Sizes are provided in MB. This version has no provision for alternate credentials.
  31. .PARAMETER Computername
  32. The name of a computer to query. The default is the local host.
  33. .EXAMPLE
  34. PS C:\> Get-Registry
  35.  
  36. Computername : SERENITY
  37. Status : OK
  38. CurrentSize : 185
  39. MaximumSize : 2048
  40. FreeSize : 1863
  41. PercentFree : 90.966796875
  42. Created : 1/28/2011 4:12:23 PM
  43. Age : 95.17:40:14.1730245
  44.  
  45. Return registry usage information for the local host.
  46. .EXAMPLE
  47. PS C:\> Get-Content Computers.txt | Get-Registry | Export-CSV c:\work\RegistryReport.csv
  48. Retrieve registry usage information for all the computers in the text file, computers.txt. The results
  49. are exported to a CSV file.
  50. .NOTES
  51. NAME : Get-Registry
  52. VERSION : 1.0
  53. LAST UPDATED: 5/4/2011
  54. AUTHOR : Jeffery Hicks
  55. .LINK
  56. http://jhdhitsolutions.com/blog/2011/05/get-registry-size-and-age
  57. .LINK
  58. Get-WMIObject
  59. .INPUTS
  60. String
  61. .OUTPUTS
  62. A custom object
  63. #>
  64.  
  65. [cmdletbinding()]
  66.  
  67. Param (
  68. [Parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
  69. [ValidateNotNullorEmpty()]
  70. [String[]]$Computername=$env:Computername
  71. )
  72.  
  73. Begin {
  74. Write-Verbose "Starting $($myinvocation.mycommand)"
  75. } #Begin
  76.  
  77. Process {
  78. Foreach ($computer in $computername) {
  79. Write-Verbose "Processing $computer"
  80. Try {
  81. #retrieve registry information via WMI
  82. $data=Get-WmiObject -Class Win32_Registry -ComputerName $computer -ErrorAction Stop
  83. #Format the results and write an object to the pipeline
  84. $data | Select-Object -Property @{Name="Computername";Expression={$_.__SERVER}},
  85. Status,CurrentSize,MaximumSize,@{Name="FreeSize";Expression={$_.MaximumSize - $_.CurrentSize}},
  86. @{Name="PercentFree";Expression={ (1 - ($_.CurrentSize/$_.MaximumSize))*100 }},
  87. @{Name="Created";Expression={$_.ConvertToDateTime($_.InstallDate)}},
  88. @{Name="Age";Expression={(Get-Date) - ( $_.ConvertToDateTime($_.InstallDate)) }}
  89.  
  90. } #try
  91.  
  92. Catch {
  93. Write-Warning "Failed to retrieve registry information from $($Computer.ToUpper())"
  94. Write-Warning $_.Exception.Message
  95. }#Catch
  96.  
  97. }#foreach $computer
  98. } #Process
  99.  
  100. End {
  101. Write-Verbose "Ending $($myinvocation.mycommand)"
  102. } #End
  103.  
  104. } #end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement