#Variables Start $ErrorActionPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue' $ScriptName = 'RTDiagnostic' $ScriptVers = '0.1' $DirBse = $Env:SystemDrive+'\RTSupport' # Base working Directory $LogName = ((Get-Date -UFormat "%Y.%m.%d_%R") -replace '[:]')+'_'+$env:COMPUTERNAME+'_'+$ScriptNme+'_v'+$ScriptVer $LogTmp = $DirBse+'\'+$LogName+'.tmp' $LogTxt = $DirBse+'\'+$LogName+'.log' # Pre-Requsite Variables $ApprovedOperatingSystems = @( 'Microsoft Windows 10 Home' 'Microsoft Windows 10 Pro' 'Microsoft Windows 11 Pro' 'Microsoft Windows 11 Home' 'Microsoft Windows 11 Business' 'Microsoft Windows Server 2012 R2 Standard' 'Microsoft Windows Server 2016 Standard' 'Microsoft Windows Server 2019 Standard' 'Microsoft Windows Server 2022 Standard' ) # $ApprovedOperatingSystems = @() # $ApprovedOperatingSystems += 'Microsoft Windows 10 Home' # $ApprovedOperatingSystems += 'Microsoft Windows 10 Pro' # $ApprovedOperatingSystems += 'Microsoft Windows 11 Pro' # $ApprovedOperatingSystems += 'Microsoft Windows 11 Home' # $ApprovedOperatingSystems += 'Microsoft Windows 11 Business' # $ApprovedOperatingSystems += 'Microsoft Windows Server 2012 R2 Standard' # $ApprovedOperatingSystems += 'Microsoft Windows Server 2016 Standard' # $ApprovedOperatingSystems += 'Microsoft Windows Server 2019 Standard' # $ApprovedOperatingSystems += 'Microsoft Windows Server 2022 Standard' # Variables End # Functions Start # Most functions that don't require security are stored in a Github public repo $gURL = 'https://raw.githubusercontent.com/RelayTechIT/RTDiag/main/' iwr -useb "$gURL`RTDiagFunctions" | iex # Functions End # Get the ID and security principal of the current user account $myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent()) # # Check if Admin $IsAdmin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544") if (!($IsAdmin)) {start powershell -verb runas -ArgumentList {iwr -useb 'diag.relaytechit.com' | IEX} Exit } # Begin the script transcript to the logfile cls Start-Transcript $LogTxt # Script Start # Ensure the Executionpolicy is set $ExecScope = "CurrentUser" $ExecPolicy = "RemoteSigned" $GetExPolicy = Get-ExecutionPolicy -Scope $ExScope if ($GetExecPolicy -eq $ExecPolicy) { Write-Host "ExecutionPolicy scope $($ExecScope) already set to $($ExecPolicy)" -ForegroundColor Green } else { Set-ExecutionPolicy -Scope $ExecScope $ExecPolicy -Force > $null Write-Host "ExecutionPolicy scope $($ExecScope) set to $($ExecPolicy)" -ForegroundColor Yellow } # Check Operating System $Info = Get-ComputerInfo $ApprovedOperatingSystems | foreach {If ($_ -match $Info.OSName) {$OSPass++}} If (!($OsPass)) { _ErrorMsg -ErrorMessage "OS: $($Info.OSName) is not an approved Operating System." } # Check for and install Required Packages or Modules _CheckForModuleOrPackage -PackageOrModuleName "NuGet" -PackageOrModuleType PackageProvider _CheckForModuleOrPackage -PackageOrModuleName "Microsoft.WinGet.Client" -PackageOrModuleType Module _CheckForModuleOrPackage -PackageOrModuleName "PSWindowsUpdate" -PackageOrModuleType Module _CheckForModuleOrPackage -PackageOrModuleName "ImportExcel" -PackageOrModuleType Module # Launch Menu if no pre-requsite errors If ($ErrN -gt 0) { _Msg -type "Fail" -message "Prerequisite tests failed. See output for details" $ErrO | foreach {_Msg -type "fail" -message $_} } else { _Msg -type "Pass" -message "All prerequsites passed" # iwr -useb 'https://raw.githubusercontent.com/RelayTechIT/RTDiag/main/RTDiag_Menu' | iex # Entries below will display in the menu of the script. # The top-most entry will be entry 1, each entry will increment by 1. # To add an entry copy the below sample entry and paste it below without the # or <> characters. # [PSCustomObject]@{DisplayName = ''; FunctionName = ''} $PreMenu = @( [PSCustomObject]@{DisplayName = 'Disk Space Cleanup'; FunctionName = 'RTDIAG-Cleanup-Disk'} [PSCustomObject]@{DisplayName = 'Clear DNS Client Cache'; FunctionName = 'RTDIAG-ClearDNSCache'} [PSCustomObject]@{DisplayName = 'Set TLS to "Best" Template using IISCryptoCli'; FunctionName = 'RTDIAG-IISCryptoCli'} [PSCustomObject]@{DisplayName = 'Get Top Processes'; FunctionName = 'RTDiag-Get-TopProcesses'} [PSCustomObject]@{DisplayName = 'Reset Windows Search Index'; FunctionName = 'RTDIAG-ResetWinSearch'} [PSCustomObject]@{DisplayName = 'Set Event Log size'; FunctionName = 'RTDiag-SetEventLogSize'} [PSCustomObject]@{DisplayName = 'Export Event Logs to Excel'; FunctionName = 'RTDiag-ExpEvLogsToXlsx'} [PSCustomObject]@{DisplayName = 'Query Users'; FunctionName = 'RTDiag-QueryUsers'} [PSCustomObject]@{DisplayName = 'IPv6 Check'; FunctionName = 'RTDiag-IPv6Check'} [PSCustomObject]@{DisplayName = 'Reset Icon Cache'; FunctionName = 'RTDiag-ResetIconCache'} [PSCustomObject]@{DisplayName = 'Reset Search Index'; FunctionName = 'RTDiag-ResetSearchIndex'} [PSCustomObject]@{DisplayName = 'Test Internet Speed'; FunctionName = 'RTDiag-Test-Bandwidth'} [PSCustomObject]@{DisplayName = 'Check System Uptime'; FunctionName = 'RTDiag-Check-System-Uptime'} [PSCustomObject]@{DisplayName = 'Check \ Fix Windows Time'; FunctionName = 'RTDiag-Check-WindowsTime'} [PSCustomObject]@{DisplayName = 'Check \ Fix Splashtop Name'; FunctionName = 'RTDiag-Check-SplashtopName'} [PSCustomObject]@{DisplayName = 'MS Teams Fix'; FunctionName = 'RTDiag-Fix-MSTeams'} [PSCustomObject]@{DisplayName = 'Set Power Management'; FunctionName = 'RTDiag-Set-PowerManagement'} [PSCustomObject]@{DisplayName = 'Apply Windows Updates'; FunctionName = 'RTDiag-WinUpdate'} [PSCustomObject]@{DisplayName = 'Enable Remote Desktop'; FunctionName = 'RTDiag-Enable-RDP'} [PSCustomObject]@{DisplayName = 'Update all MS Store Apps (AppxPackages)'; FunctionName = 'RTDIAG-Update-AppxPackages'} [PSCustomObject]@{DisplayName = 'Update Chocolatey Packages'; FunctionName = 'RTDiag-ChocoUpdate'} [PSCustomObject]@{DisplayName = 'Fix Active Backup Errors'; FunctionName = 'RTDiag-Check-ActiveBackup'} [PSCustomObject]@{DisplayName = 'Disk Space Cleanup'; FunctionName = 'RTDiag-Disk-Cleanup'} [PSCustomObject]@{DisplayName = 'Check Disk for Issues'; FunctionName = 'RTDiag-Check-Disks'} [PSCustomObject]@{DisplayName = 'Local Security Checks'; FunctionName = 'RTDIAG-LocalSecurityChecks'} [PSCustomObject]@{DisplayName = 'DoD DISA SCAP Scan v5.12.1'; FunctionName = 'RTDiag-SCAPScan-v5.12.1'} [PSCustomObject]@{DisplayName = 'Remove Microsoft OneDrive'; FunctionName = 'RTDiag-Remove-MSOneDrive'} [PSCustomObject]@{DisplayName = 'Remove Microsoft Teams'; FunctionName = 'RTDiag-Remove-MSTeams'} [PSCustomObject]@{DisplayName = 'BETA - Remove User Profiles'; FunctionName = 'RTDIAG-Remove-UserProfiles'} ) $n = 1 $Menu = @( $PreMenu | foreach { [PSCustomObject]@{Prompt = $n; DisplayName = $_.DisplayName; FunctionName = $_.FunctionName; Selected = 0} $n++ } ) While (1) { Write-Host "Relay Tech Diagnostic version: $($ScriptVers)" Write-Host "Computername: $($Info.CsDNSHostName)" Write-Host "Make\Model: $($Info.CsManufacturer) $($Info.CsProcessors)" Write-Host "Processor: $($Info.CsProcessors)" Write-Host "Memory: $($Info.CsTotalPhysicalMemory)" Write-Host "" Write-Host "Select an option to continue:" $Menu | foreach { If ($_.Selected -eq 0) { Write-Host " " $_.Prompt " - " $_.DisplayName } else { Write-Host " X - " $_.DisplayName " (Already Run)" -ForegroundColor Green } } Write-Host "" Write-Host " 99 - End Script" Write-Host "" $c = Read-Host If ($c -eq 99) { Write-Host "Exiting Menu." -foregroundcolor yellow; Break; } elseif (($menu | where Prompt -eq $c).Selected -ne 0) { Write-Host "Option" ($Menu | where Prompt -eq $c).FunctionName "previously selected. Pick another option." -foregroundcolor yellow } elseif (($menu | where Prompt -eq $c).Selected -eq 0) { Write-Host "Running " ($Menu | where Prompt -eq $c).FunctionName -foregroundcolor yellow ($menu | where Prompt -eq $c).selected = 1 $url = $gURL+($Menu | where Prompt -eq $c).FunctionName; iwr -useb $url | iex } else { Write-Host "Incorrect Selection. Pick again." -foregroundcolor yellow } Write-Host "" Write-Host "Finished running" ($Menu | where Prompt -eq $c).FunctionName "Press any key to go back to the main menu." -foreground yellow pause } }