Code/Remove-IntelliTraceFile.ps1
#requires -version 5.0 ############################################################################### # WintellectPowerShell Module # Copyright (c) 2010-2017 - John Robbins/Wintellect # # Do whatever you want with this module, but please do give credit. ############################################################################### # Always make sure all variables are defined and all best practices are # followed. Set-StrictMode -version Latest ############################################################################### # Public Cmdlets ############################################################################### function Remove-IntelliTraceFiles { <# .SYNOPSIS Removes extra IntelliTrace files that may have been left over from your debugging sessions. .DESCRIPTION Best practice with day to day debugging with IntelliTrace is to have the debugger store the IntelliTrace files. This is important because you will gain the ability to open the files after debugging. This option is not on by default, but can be turned on by going to the VS Options dialog, IntelliTrace, Advanced property page and checking "Store IntelliTrace recordings in this directory." Once you have your IntelliTrace files being saved you have a small issue that VS does not always properly clean up the files after shutting down. This cmdlet checks to see if you are storing the files and if you are, deletes any files found in the storage directory. Since IntelliTrace files can take up a lot of disk space, it's good to clean out that directory every once in a while. By default, this script works with Visual Studio 2013, 2015 and 2017 with the default being VS 2017. .PARAMETER VSVersion Removes the stored IntelliTrace files for VS 2017 by default, specify VS 2013 or VS 2015 for those versions. .LINK http://www.wintellect.com/devcenter/author/jrobbins https://github.com/Wintellect/WintellectPowerShell #> [CmdLetBinding(SupportsShouldProcess=$true)] # I hate suppressing this warning, but I created this cmdlet long before the # script analyzer came out. If someone has this in a script, changing the # cmdlet name will break them. [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Scope="Function")] param ( [ValidateSet("VS2013", "VS2015", "VS2017", "Latest")] [string] $VSVersion = "Latest" ) # First check if VS is running. If so, we can't continue as it may be using # the .iTrace files. $proc = Get-Process -Name devenv -ErrorAction SilentlyContinue if ($null -ne $proc) { throw "Visual Studio is running. Please close all instances." } # Default to VS 2017. $regVer = "15.0" switch ($VSVersion) { "VS2013" { $regVer = "12.0" } "VS2015" { $regVer = "14.0" } "VS2017" { $regVer = "15.0" } "Latest" { $regVer = LatestVSRegistryKeyVersion } } [string]$storageDir = "" # Am I supposed to look for VS 2017 or higher? If so, we have work to do because VS 2017 completely changed the # way version detection and the registry are handled. These changes are excellent for performance, but cause # more work on my side. Oh well. :) if ($regVer -lt "15.0") { # Handle older versions of Visual Studio. $regKey = "HKCU:\SOFTWARE\Microsoft\VisualStudio\$regVer\ApplicationPrivateSettings\Microsoft\VisualStudio\TraceLogPackage\ToolsOptionAdvanced" if ($regVer -lt "14.0") { $regKey = "HKCU:\Software\Microsoft\VisualStudio\" + $regVer + "\DialogPage\Microsoft.VisualStudio.TraceLogPackage.ToolsOptionAdvanced" } # Check to see if the user has set the options to save files. If not bail out. if (((Test-PathReg -Path $regKey -Property "SaveRecordings") -eq $false) -or ((Get-ItemProperty -Path $regKey).SaveRecordings -match "False")) { throw "You have not configured IntelliTrace to save recordings. " + "In the Options dialog, IntelliTtrace Advanced page, check the " + "Store IntelliTrace recordings in this directory check box." } if ((Test-PathReg -Path $regKey -Property "RecordingPath") -ne $false) { # Get the storage directory for those files. $storageDir = (Get-ItemProperty -Path $regKey).RecordingPath } # If this is version 14.0 or greater it will have some gunk on the beginning. if ($storageDir.StartsWith("1*System.String*")) { $storageDir = $storageDir.Substring("1*System.String*".Length) } } else { # OK, I'm supposed to do the spiffy new versions. # 1. See if any VS 2017 versions are installed and if any are Enterprise versions # Load my helper that wraps the VS 2017+ setup configuration component. $loadResult = Get-ChildItem -Path $PSScriptRoot -File "WintellectPowerShellHelper.DLL" -ErrorAction Stop | ForEach-Object {[Reflection.Assembly]::LoadFile($_.FullName)} if ($null -eq $loadResult) { throw "Unable to find the required WintellectPowerShellHelper.DLL in the WintellectPowerShell module directory" } $vsInstalls = [WintellectPowerShellHelper.VisualStudioSetup]::GetInstalledInstances() if ($vsInstalls.Count -eq 0) { throw "No Visual Studio 2017+ instances installed on this computer" } # 2. Get the instance ID for the Enterprise version that matches the one the user want to clean up. $vsToProcess = $null for ($i = 0; $i -lt $vsInstalls.Count; $i++) { if (($vsInstalls[$i].ProductName.Contains("Enterprise")) -and ($vsInstalls[$i].InstalledVersionNumber.Substring(0,2) -eq $regVer.SubString(0,2))) { $vsToProcess = $vsInstalls[$i] break } } if ($null -eq $vsToProcess) { throw "The Visual Studio version you requested is not an Enterprise edition" } # 3. Open the registry file in privateregistry.bin and read the value. $regFilePath = $env:LOCALAPPDATA + "\Microsoft\VisualStudio\" + $regVer + "_" + $vsToProcess.InstanceId + "\privateregistry.bin" if (! (Test-Path $regFilePath)) { throw "The privateregistry.bin file does not exist" } $regKey = "Software\Microsoft\VisualStudio\15.0_" + $vsToProcess.InstanceId + "\ApplicationPrivateSettings\Microsoft\VisualStudio\TraceLogPackage\ToolsOptionAdvanced" $storageDir = [WintellectPowerShellHelper.PrivateRegistry]::ReadValue($regFilePath, $regKey, "RecordingPath") if ($storageDir.StartsWith("1*System.String*")) { $storageDir = $storageDir.Substring("1*System.String*".Length) } } if ($storageDir.Length -eq 0) { throw "The IntelliTrace recording directory is empty. Check the " + "Options dialog, IntelliTrace Advanced page to set the "+ "directory." } if ($PSCmdlet.ShouldProcess($storageDir,"Deleting files in")) { # Clean up those files but only do the ones in the main directory so if the # user may have created paths and put other files there we don't delete those. Get-ChildItem -Path $storageDir -Filter "*.iTrace" | Remove-Item -Force } } # SIG # Begin signature block # MIIUywYJKoZIhvcNAQcCoIIUvDCCFLgCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUGFtrotEPc58Tn6zgjTibodby # PZ2ggg+6MIIEmTCCA4GgAwIBAgIPFojwOSVeY45pFDkH5jMLMA0GCSqGSIb3DQEB # BQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNhbHQg # TGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxITAfBgNV # BAsTGGh0dHA6Ly93d3cudXNlcnRydXN0LmNvbTEdM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