Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires -version 2.0
- # -----------------------------------------------------------------------------
- # Script: get-registry.ps1
- # Version: 1.0
- # Author: Jeffery Hicks
- # http://jdhitsolutions.com/blog
- # http://twitter.com/JeffHicks
- # http://www.ScriptingGeek.com
- # Date: 5/4/2011
- # Keywords: Registry, WMI
- # Comments:
- #
- # "Those who forget to script are doomed to repeat their work."
- #
- # ****************************************************************
- # * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
- # * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF *
- # * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
- # * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. *
- # ****************************************************************
- # -----------------------------------------------------------------------------
- Function Get-Registry {
- <#
- .SYNOPSIS
- Get registry size and utilization
- .DESCRIPTION
- 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.
- .PARAMETER Computername
- The name of a computer to query. The default is the local host.
- .EXAMPLE
- PS C:\> Get-Registry
- Computername : SERENITY
- Status : OK
- CurrentSize : 185
- MaximumSize : 2048
- FreeSize : 1863
- PercentFree : 90.966796875
- Created : 1/28/2011 4:12:23 PM
- Age : 95.17:40:14.1730245
- Return registry usage information for the local host.
- .EXAMPLE
- PS C:\> Get-Content Computers.txt | Get-Registry | Export-CSV c:\work\RegistryReport.csv
- Retrieve registry usage information for all the computers in the text file, computers.txt. The results
- are exported to a CSV file.
- .NOTES
- NAME : Get-Registry
- VERSION : 1.0
- LAST UPDATED: 5/4/2011
- AUTHOR : Jeffery Hicks
- .LINK
- http://jhdhitsolutions.com/blog/2011/05/get-registry-size-and-age
- .LINK
- Get-WMIObject
- .INPUTS
- String
- .OUTPUTS
- A custom object
- #>
- [cmdletbinding()]
- Param (
- [Parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
- [ValidateNotNullorEmpty()]
- [String[]]$Computername=$env:Computername
- )
- Begin {
- Write-Verbose "Starting $($myinvocation.mycommand)"
- } #Begin
- Process {
- Foreach ($computer in $computername) {
- Write-Verbose "Processing $computer"
- Try {
- #retrieve registry information via WMI
- $data=Get-WmiObject -Class Win32_Registry -ComputerName $computer -ErrorAction Stop
- #Format the results and write an object to the pipeline
- $data | Select-Object -Property @{Name="Computername";Expression={$_.__SERVER}},
- Status,CurrentSize,MaximumSize,@{Name="FreeSize";Expression={$_.MaximumSize - $_.CurrentSize}},
- @{Name="PercentFree";Expression={ (1 - ($_.CurrentSize/$_.MaximumSize))*100 }},
- @{Name="Created";Expression={$_.ConvertToDateTime($_.InstallDate)}},
- @{Name="Age";Expression={(Get-Date) - ( $_.ConvertToDateTime($_.InstallDate)) }}
- } #try
- Catch {
- Write-Warning "Failed to retrieve registry information from $($Computer.ToUpper())"
- Write-Warning $_.Exception.Message
- }#Catch
- }#foreach $computer
- } #Process
- End {
- Write-Verbose "Ending $($myinvocation.mycommand)"
- } #End
- } #end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement