Get-HTSupportInfo.ps1
function Get-HTSupportInfo { [CmdletBinding()] param ( # If Set, logs will be delete before Collecting Info. [switch] $ClearLogsFirst, #If Set, Only logs will be collected, overrides FilePatterns Option. [switch] $OnlyLogs, # Base Folder Path To Gather Log Files. [Parameter(Position=1)] [string] $BasePath = 'C:\Program Files\CSM', # File Filter For Files default is "*.log" [Parameter(Position=2)] [string[]] $FilePatterns = @('*.log', '*.db', '*.config') ) process { $invokeInfo = @() $invokeInfo += "Command Invoked at $(Get-Date)" $invokeInfo += "Base path is set as $BasePath" $invokeInfo += "File Patterns is set as $FilePatterns" if($ClearLogsFirst) { $invokeInfo += "Clear Logs First switch is set. Starting to delete Logs $(Get-Date)" Clear-HTLogFiles $invokeInfo += "Logs Cleared, starting to wait for collection confirmation $(Get-Date)" Read-Host -Prompt "When Ready Press Enter to Collect Support Information..." $invokeInfo += "Starting to Collect Logs $(Get-Date)" } if($OnlyLogs) {$FilePatterns = @('*.log'); $invokeInfo += "Only Logs Switch Set"} $dateSuffix = Get-Date -Format 'ddMMyyyyHHmmss' $hostname = hostname $tempFolder = New-HTTempFolder -FolderName "$hostname-$dateSuffix" foreach($FileFilter in $FilePatterns) { $filterFriendlyName = $FileFilter -replace "[\*\.]" Write-Progress -Activity "Searching $filterFriendlyName Files" -Status "Searching" -PercentComplete 0; $files = Get-ChildItem -Path $BasePath -Filter $FileFilter -Recurse $total = $files.Count $progress = 0 foreach($f in $files) { $percentComplete = $progress/$total*100 Write-Progress -Activity "Copying $filterFriendlyName Files" -Status $f.FullName -PercentComplete $percentComplete; $dir = $f.Directory $splitted = $dir.FullName.Split('\') $t = $splitted[-3] + '-' + $splitted[-2] + '-' + $splitted[-1] $t = $t + '-' + $f.Name $tempPatternFolder = Join-Path $tempFolder $filterFriendlyName if(!$(Test-Path $tempPatternFolder)) { Write-Verbose "$tempPatternFolder not exists creating..." New-Item $tempPatternFolder -ItemType Directory | Out-Null } $t = Join-Path $tempPatternFolder $t Write-Verbose "Full Name: $($f.FullName) Target: $t" Copy-Item $f.FullName $t $progress++ } } $invokeInfo += "Collection Finished at $(Get-Date)" Out-File -InputObject $invokeInfo -FilePath $(Join-Path $tempFolder "InvokeInfo.txt") -Encoding utf8 Compress-Archive -Path $tempFolder -DestinationPath "SupportInfo-$dateSuffix" Remove-HTTempFolder -FolderName $tempFolder.Name } } |