Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -version 2.0
- #First Run issues
- # -----------------------------------------------------------------------------
- #Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
- #AllSigned - Only scripts signed by a trusted publisher can be run.
- #RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
- #Unrestricted - No restrictions; all Windows PowerShell scripts can be run.
- #
- #Set-ExecutionPolicy Unrestricted
- #Set-ExecutionPolicy “Unrestricted” -Scope CurrentUser -Confirm:$false
- #
- #$PSVersionTable.PSVersion get current version
- # -----------------------------------------------------------------------------
- #Reference Links
- #https://msdn.microsoft.com/en-us/library/aa394394(v=vs.85).aspx
- #https://books.google.ca/books?id=DD1jA3RgFEMC&pg=PA216&lpg=PA216&dq=Win32_Registry+currentSize&source=bl&ots=FOBI7NUgEQ&sig=zLw5f5i9VGpeHnie0Z05vuBDLco&hl=en&sa=X&ved=0ahUKEwjmyfrx1d3NAhVowYMKHUVtC2cQ6AEINTAE#v=onepage&q=Win32_Registry%20currentSize&f=false
- # size in MB
- # -----------------------------------------------------------------------------
- # Script: get-RegistrySizeAge.ps1
- # Version: 1.2017.05.03
- # Author: Mark Pahulje
- # http://metadataconsulting.blogspot.com/
- # Date: 08-Apr-2017
- # Keywords: Registry, WMI, Size, Age
- # 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-RegistrySizeAge {
- <#
- .SYNOPSIS
- Get registry size, status, utilization and age
- .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-RegistrySizeAge
- 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-RegistrySizeAge
- VERSION : 1.2017.05.03
- LAST UPDATED: 5/3/2017
- AUTHOR : Mark Pahulje
- .LINK
- http://metadataconsulting.blogspot.ca/2016/07/windows-10-registry-size-number-of-keys-number-of-key-value-pairs.html
- .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
- #@{Name="Computername";Expression={$_.__SERVER}},
- Process {
- Write-Host "`r`nGet Registry Age and Size running on " (Get-WmiObject -class Win32_OperatingSystem).Caption -BackgroundColor Red
- Foreach ($computer in $computername) {
- Write-Verbose "Processing $computer"
- Try {
- #retrieve registry information via WMI
- $data=Get-WmiObject -Class Win32_Registry -ComputerName $computer -ErrorAction Stop
- #direct call to .NET library
- [datetime]$InstallDateMngmtDTC = [System.Management.ManagementDateTimeConverter]::ToDateTime(($data).InstallDate)
- Add-Member -InputObject $data -MemberType NoteProperty -Name InstallDateMngmtDTC -Value $InstallDateMngmtDTC
- #Format the results and write an object to the pipeline
- #All members here https://msdn.microsoft.com/en-us/library/aa394394(v=vs.85).aspx
- $data | Select-Object -Property @{Name="Registry Name";Expression={$_.Name}},
- @{Name="Registry Status";Expression={$_.Status}},
- #@{Name="Registry Description";Expression={$_.Description}},
- #@{Name="Registry Caption";Expression={$_.Caption}},
- @{Name="Current Size";Expression={"{0:N0} Mb" -f ($_.CurrentSize)}},
- @{Name="Free Size";Expression={"{0:N0} Mb" -f ($_.MaximumSize - $_.CurrentSize)}},
- @{Name="Maximum Size";Expression={"{0:N0} Mb" -f ($_.MaximumSize)}},
- @{Name="Percent Used";Expression={"{0:N1} %" -f ( $_.CurrentSize/$_.MaximumSize*100 )}},
- @{Name="Percent Free";Expression={"{0:N1} %" -f ( (1 - ($_.CurrentSize/$_.MaximumSize))*100 )}},
- @{Name="Created";Expression={$_.ConvertToDateTime($_.InstallDate)}},
- @{Name="Age";Expression={(Get-Date) - ( $_.ConvertToDateTime($_.InstallDate)) }},
- @{Name="Age Formatted";Expression={"{1:N0} years, {2:N0} months, {3:N0} days & {0:hh} hours, {0:mm} mins, {0:ss} secs, {0:fff} msecs" -f ( ((Get-Date) - ($_.InstallDateMngmtDTC)), [Math]::Truncate( (((Get-Date) - ($_.InstallDateMngmtDTC)).Days/365.2425) ), [Math]::Truncate( ((((Get-Date) - ($_.InstallDateMngmtDTC)).Days%365.2425)/30.436875)), ((((Get-Date) - ($_.InstallDateMngmtDTC)).Days%30.436875)) ) }}
- } #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
- get-RegistrySizeAge
Advertisement
Add Comment
Please, Sign In to add comment