This commit is contained in:
2020-08-18 16:20:20 -04:00
parent 98fb3928c5
commit cb110b354d
26 changed files with 225 additions and 201 deletions
+9
View File
@@ -0,0 +1,9 @@
## This script will remove runaway AppX temp files that can consume 100's of GB on an endpoint
## Only run this script on Windows 8 or higher endpoints
$WindowsVersion = [double]("{0}.{1}" -f ([System.Environment]::OSVersion.Version).Major,([System.Environment]::OSVersion.Version).Minor)
If ( $WindowsVersion -ge 6.2 )
{
Get-ChildItem -Path "${Env:SystemRoot}\Temp" | Where { $_.Name -like "AppXDeploymentServer_*.evtx" }| Remove-Item -Force
Get-ChildItem -Path "${Env:SystemRoot}\Temp" | Where { $_.Name -like "AppxErrorReport_*.txt" } | Remove-Item -Force
Get-ChildItem -Path "${Env:SystemRoot}\Temp" | Where { $_.Name -like "AppXPackaging_*.evtx" }| Remove-Item -Force
}
+2
View File
@@ -0,0 +1,2 @@
## This script will delete runaway CBS logs that can take up 100's of GB on an endpoint
Get-ChildItem -Path "${Env:WINDIR}\Logs\CBS" -File | Where { ( $_.Name -like "CbsPersist_*.log" ) -or ( $_.Name -like "CbsPersist_*.cab" ) } | Remove-Item -Force
+24
View File
@@ -0,0 +1,24 @@
## Get contents of SYSTEM PATH environment variable
$REG_ENVVAR = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
$CURRENT_PATH = (Get-Itemproperty -Path $REG_ENVVAR -Name Path).Path
$NEW_PATH = $null
$REMOVE_PATH =$null
## Verify each path
Foreach ( $path in $CURRENT_PATH.Split(";") )
{
If ( (Test-Path $path) -or ($path -like "*%*%*") )
{
If ( $NEW_PATH ) { $NEW_PATH += ";${path}" }
Else { $NEW_PATH = $path }
}
Else
{
If ( $REMOVE_PATH ) { $REMOVE_PATH += ";${path}" }
Else { $REMOVE_PATH = $path }
}
}
Write-Output "Removed Paths:`n`r${REMOVE_PATH}"
Set-ItemProperty -Path $REG_ENVVAR -Name Path -Value $NEW_PATH
+13
View File
@@ -0,0 +1,13 @@
[CmdletBinding()]
param([int]$OlderThan=7)
## Create a new timespan to compare with last write date of the target directory
$timedelta = New-TimeSpan -Days $OlderThan
## Remove all files and directories
Foreach ( $item in (Get-ChildItem -Path "${Env:WinDir}\TEMP") )
{
## If it's older than the number of days specified, recursively delete the directory
If ( $item.LastWriteTime -lt ((Get-Date) - $timedelta) ) { Remove-Item $item.FullName -Recurse -ErrorAction SilentlyContinue -Force }
}
+16 -13
View File
@@ -9,10 +9,13 @@ $ModuleURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/ma
## Setup the MSP management directories
If ( Test-Path ${Env:ProgramData} )
{ $RootDir = "${Env:ProgramData}\${MSPName}" } Else { $RootDir = "${Env:SystemDrive}\${MSPName}" }
{ $MSPRoot = "${Env:ProgramData}\${MSPName}" } Else { $MSPRoot = "${Env:SystemDrive}\${MSPName}" }
$MSPScripts = "${MSPRoot}\Scripts"
$MSPTools = "${MSPRoot}\Tools"
$MSPLogs = "${MSPRoot}\Logs"
## Set the path to this module and make the directory for it
$ModulePath = "${RootDir}\Scripts\${ModuleName}"
$ModulePath = "${MSPRoot}\Scripts\${ModuleName}"
## Create the path to the module
If ( !(Test-Path $ModulePath) )
@@ -22,33 +25,33 @@ If ( !(Test-Path $ModulePath) )
}
## Set the environment variable to the module
[System.Environment]::SetEnvironmentVariable('MSPPSModule',"${RootDir}\Scripts\${ModuleName}",[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('MSPPSModule',"${MSPRoot}\Scripts\${ModuleName}",[System.EnvironmentVariableTarget]::Machine)
## Make sure all the management directories exist
If ( !(Test-Path $RootDir) )
If ( !(Test-Path $MSPRoot) )
{
Try { New-Item -Path $RootDir -ItemType Directory -Force | Out-Null }
Try { New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path "${RootDir}\Scripts") )
If ( !(Test-Path $MSPScripts) )
{
Try { New-Item -Path "${RootDir}\Scripts" -ItemType Directory -Force | Out-Null }
Try { New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path "${RootDir}\Tools") )
If ( !(Test-Path $MSPTools) )
{
Try { New-Item -Path "${RootDir}\Tools" -ItemType Directory -Force | Out-Null }
Try { New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path "${RootDir}\Logs") )
If ( !(Test-Path $MSPLogs) )
{
Try { New-Item -Path "${RootDir}\Logs" -ItemType Directory -Force | Out-Null }
Try { New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
## Create environment variable for the root MSP directory
[System.Environment]::SetEnvironmentVariable('MSPDir',"${RootDir}",[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('MSPDir',"${MSPRoot}",[System.EnvironmentVariableTarget]::Machine)
## Download the module file
Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, "${RootDir}\Scripts\${ModuleName}\${ModuleName}.psm1") }
Try { (New-Object Net.WebClient).DownloadFile($ModuleURL, "${MSPRoot}\Scripts\${ModuleName}\${ModuleName}.psm1") }
Catch { Write-Output $_.Exception.Message }
+22
View File
@@ -0,0 +1,22 @@
## Make sure the spooler service isn't already stopped
If ( (Get-Service -Name spooler).Status -ne "Stopped" )
{
## Forcefully stop the spooler service
Stop-Service -Name spooler -Force
## Wait a few seconds to make sure it's stopped
Start-Sleep -Seconds 5
}
## Check to make sure the spooler service has stopped
If ((Get-Service -Name spooler).Status -eq "Stopped")
{
## Delete all print jobs, including secure prints
Remove-Item "${Env:WINDIR}\System32\spool\PRINTERS\*" -Recurse
## Start the spooler service again
Start-Service -Name spooler
}
## If the spooler service didn't stop on time, just return an error
Else { Write-Output "Could not clean ${Env:WINDIR}\System32\spool\PRINTERS\* because spooler service is running." }
+36
View File
@@ -0,0 +1,36 @@
## List of all scripting component DLL files
$DLL_FILES = @("${Env:WINDIR}\system32\vbscript.dll",
"${Env:WINDIR}\system32\jscript.dll",
"${Env:WINDIR}\system32\dispex.dll",
"${Env:WINDIR}\system32\scrobj.dll",
"${Env:WINDIR}\system32\scrrun.dll",
"${Env:WINDIR}\system32\wshext.dll"
"${Env:WINDIR}\system32\wshom.ocx",
"${Env:WINDIR}\syswow64\vbscript.dll",
"${Env:WINDIR}\syswow64\jscript.dll",
"${Env:WINDIR}\syswow64\dispex.dll",
"${Env:WINDIR}\syswow64\scrobj.dll",
"${Env:WINDIR}\syswow64\scrrun.dll",
"${Env:WINDIR}\syswow64\wshext.dll",
"${Env:WINDIR}\syswow64\wshom.ocx")
## Unregister all DLLs
ForEach ($dll in $DLL_FILES)
{
If ( Test-Path $dll )
{
If ( $dll -Match "syswow64" ) { $REGSVR32 = "${Env:WINDIR}\syswow64\regsvr32" } Else { $REGSVR32 = "regsvr32" }
Start-Process "${REGSVR32}" -ArgumentList "/u /s ${dll}" -Wait
}
}
## Register all DLLs
ForEach ($dll in $DLL_FILES)
{
If ( Test-Path $dll )
{
If ( $dll -Match "syswow64" )
{ $REGSVR32 = "${Env:WINDIR}\syswow64\regsvr32" } Else { $REGSVR32 = "regsvr32" }
Start-Process "${REGSVR32}" -ArgumentList "/s ${dll}" -Wait
}
}
+21
View File
@@ -0,0 +1,21 @@
param([switch]$WSUS)
## Delete any existing folder from a previous execution of this script
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" ) { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
## Stop Background Intelligent Transfer Services and Windows Update
Stop-Service BITS
Stop-Service wuauserv
## Rename the SoftwareDistribution folder, forcing Windows Update to recreate all metrics and redownload all updates
Rename-Item -Path "${Env:WinDir}\SoftwareDistribution" -NewName "${Env:WinDir}\SoftwareDistribution.old" -Force
## Start Windows Update and Background Intelligent Transfer Services
Start-Service wuauserv
Start-Service BITS
## Delete SoftwareDistribution.old from this execution of this script
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" ) { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
## If using WSUS, reset authorization with server and detect new updates
If ( $WSUS ) { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" }
-63
View File
@@ -1,63 +0,0 @@
Function global:Cleanup-SystemPath
{
## Get contents of SYSTEM PATH environment variable
$REG_ENVVAR = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
$CURRENT_PATH = (Get-Itemproperty -Path $REG_ENVVAR -Name Path).Path
$NEW_PATH = $null
$REMOVE_PATH =$null
## Verify each path
Foreach ( $path in $CURRENT_PATH.Split(";") )
{
If ( (Test-Path $path) -or ($path -like "*%*%*") )
{
If ( $NEW_PATH ) { $NEW_PATH += ";${path}" }
Else { $NEW_PATH = $path }
}
Else
{
If ( $REMOVE_PATH ) { $REMOVE_PATH += ";${path}" }
Else { $REMOVE_PATH = $path }
}
}
Write-Output "Removed Paths:`n`r${REMOVE_PATH}"
Set-ItemProperty -Path $REG_ENVVAR -Name Path -Value $NEW_PATH
}
## This script will remove runaway AppX temp files that can consume 100's of GB on an endpoint
Function global:Cleanup-AppXTempFiles
{
## Only run this script on Windows 8 or higher endpoints
$WindowsVersion = [double]("{0}.{1}" -f ([System.Environment]::OSVersion.Version).Major,([System.Environment]::OSVersion.Version).Minor)
If ( $WindowsVersion -ge 6.2 )
{
Get-ChildItem -Path "${Env:SystemRoot}\Temp" | Where { $_.Name -like "AppXDeploymentServer_*.evtx" }| Remove-Item -Force
Get-ChildItem -Path "${Env:SystemRoot}\Temp" | Where { $_.Name -like "AppxErrorReport_*.txt" } | Remove-Item -Force
Get-ChildItem -Path "${Env:SystemRoot}\Temp" | Where { $_.Name -like "AppXPackaging_*.evtx" }| Remove-Item -Force
}
}
## This script will delete runaway CBS logs that can take up 100's of GB on an endpoint
Function global:Cleanup-LogFiles
{
Get-ChildItem -Path "${Env:WINDIR}\Logs\CBS" -File | Where { ( $_.Name -like "CbsPersist_*.log" ) -or ( $_.Name -like "CbsPersist_*.cab" ) } | Remove-Item -Force
}
Function global:Cleanup-TempFiles
{
#[CmdletBinding()]
param([int]$OlderThan=7)
## Create a new timespan to compare with last write date of the target directory
$timedelta = New-TimeSpan -Days $OlderThan
## Remove all files and directories
Foreach ( $item in (Get-ChildItem -Path "${Env:WinDir}\TEMP") )
{
## If it's older than the number of days specified, recursively delete the directory
If ( $item.LastWriteTime -lt ((Get-Date) - $timedelta) ) { Remove-Item $item.FullName -Recurse -ErrorAction SilentlyContinue -Force }
}
}
-90
View File
@@ -1,90 +0,0 @@
Function global:Fix-WindowsScriptingComponents
{
## List of all scripting component DLL files
$DLL_FILES = @("${Env:WINDIR}\system32\vbscript.dll",
"${Env:WINDIR}\system32\jscript.dll",
"${Env:WINDIR}\system32\dispex.dll",
"${Env:WINDIR}\system32\scrobj.dll",
"${Env:WINDIR}\system32\scrrun.dll",
"${Env:WINDIR}\system32\wshext.dll"
"${Env:WINDIR}\system32\wshom.ocx",
"${Env:WINDIR}\syswow64\vbscript.dll",
"${Env:WINDIR}\syswow64\jscript.dll",
"${Env:WINDIR}\syswow64\dispex.dll",
"${Env:WINDIR}\syswow64\scrobj.dll",
"${Env:WINDIR}\syswow64\scrrun.dll",
"${Env:WINDIR}\syswow64\wshext.dll",
"${Env:WINDIR}\syswow64\wshom.ocx")
## Unregister all DLLs
ForEach ($dll in $DLL_FILES)
{
If ( Test-Path $dll )
{
If ( $dll -Match "syswow64" ) { $REGSVR32 = "${Env:WINDIR}\syswow64\regsvr32" } Else { $REGSVR32 = "regsvr32" }
Start-Process "${REGSVR32}" -ArgumentList "/u /s ${dll}" -Wait
}
}
## Register all DLLs
ForEach ($dll in $DLL_FILES)
{
If ( Test-Path $dll )
{
If ( $dll -Match "syswow64" )
{ $REGSVR32 = "${Env:WINDIR}\syswow64\regsvr32" } Else { $REGSVR32 = "regsvr32" }
Start-Process "${REGSVR32}" -ArgumentList "/s ${dll}" -Wait
}
}
}
Function global:Fix-SystemPrintQueue
{
## Make sure the spooler service isn't already stopped
If ( (Get-Service -Name spooler).Status -ne "Stopped" )
{
## Forcefully stop the spooler service
Stop-Service -Name spooler -Force
## Wait a few seconds to make sure it's stopped
Start-Sleep -Seconds 5
}
## Check to make sure the spooler service has stopped
If ((Get-Service -Name spooler).Status -eq "Stopped")
{
## Delete all print jobs, including secure prints
Remove-Item "${Env:WINDIR}\System32\spool\PRINTERS\*" -Recurse
## Start the spooler service again
Start-Service -Name spooler
}
## If the spooler service didn't stop on time, just return an error
Else { Write-Output "Could not clean ${Env:WINDIR}\System32\spool\PRINTERS\* because spooler service is running." }
}
Function global:Fix-WindowsUpdate
{
param([switch]$WSUS)
## Delete any existing folder from a previous execution of this script
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" ) { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
## Stop Background Intelligent Transfer Services and Windows Update
Stop-Service BITS
Stop-Service wuauserv
## Rename the SoftwareDistribution folder, forcing Windows Update to recreate all metrics and redownload all updates
Rename-Item -Path "${Env:WinDir}\SoftwareDistribution" -NewName "${Env:WinDir}\SoftwareDistribution.old" -Force
## Start Windows Update and Background Intelligent Transfer Services
Start-Service wuauserv
Start-Service BITS
## Delete SoftwareDistribution.old from this execution of this script
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" ) { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
## If using WSUS, reset authorization with server and detect new updates
If ( $WSUS ) { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" }
}
@@ -40,7 +40,7 @@ Function global:Set-WinEvtLog {
Begin
{
# Keep track of changes made to event logs in a separate file.
$RecordLog = "${Env:MSPLogs}\WinEvtLogs-Enabled.log"
$RecordLog = "${Env:MSPDir}\Logs\WinEvtLogs-Enabled.log"
If ( !(Test-Path -Path $RecordLog) )
{
+68 -13
View File
@@ -9,6 +9,12 @@ $BaseURL = "https://dev.emberkom.com/emberkom/management-scripts/raw/branch/mast
## Set the path to this module
$ModulePath = "${Env:MSPDir}\Scripts\${ModuleName}"
## Define the paths for where we'll place stuff on the endpoint
$MSPRoot = $Env:MSPDir
$MSPScripts = "${MSPRoot}\Scripts"
$MSPTools = "${MSPRoot}\Tools"
$MSPLogs = "${MSPRoot}\Logs"
## Function to simply import a module and return an error message if it fails
Function Load-Module
{
@@ -47,6 +53,30 @@ Function Get-Module
} Else { Write-Output "Could not download ${ModuleURL}" }
}
## Function to retrieve and run a script
Function Run-Script
{
param(
[string]$Type='management-scripts',
[string]$Name,
[string]$Arguments
)
## Form the URL to the specified script
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
If ( IsDownloadable $URL )
{
$Type = 'management-scripts'
$Name = "test"
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
$Script = (New-Object Net.WebClient).DownloadString($URL)
$ScriptBlock = [Scriptblock]::Create($Script)
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
Catch { Write-Output $_.Exception.Message }
} Else { Write-Output "Could not retrieve ${URL}" }
}
## Determines whether a file can be downloaded or not
Function IsDownloadable
{
@@ -76,7 +106,7 @@ Function IsDownloadable
}
## EXPORT FUNCTION
## Function to log activity to the configured $LogDir
## Function to log activity to the configured log directory
Function global:Log
{
Begin {}
@@ -84,22 +114,47 @@ Function global:Log
End {}
}
## EXPORT FUNCTION
## Function to determine if the current user context is an Administrator
Function global:IsAdmin
{
Begin {}
Process
{
If ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) )
{ Return $true } Else { Return $false }
}
End {}
}
## Make sure all the management directories exist
If ( !(Test-Path $MSPRoot) )
{
Try { New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path $MSPScripts) )
{
Try { New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path $MSPTools) )
{
Try { New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
If ( !(Test-Path $MSPLogs) )
{
Try { New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null }
Catch { Write-Output $_.Exception.Message }
}
## Import all modules
$ListOfModules = @(
"PSModule",
"PSModule-Cleanup",
"PSModule-Create",
"PSModule-Fix",
"PSModule-Get",
"PSModule-Install",
"PSModule-Remediation",
"PSModule-Remove",
"PSModule-Set",
"PSModule-Start",
"PSModule-Uninstall",
"PSModule-Upload"
"PSModule-SetWinEvtLog"
)
ForEach ($module in $ListOfModules) { Load-Module $module }
## Make sure this module exports only the functions that should be exported
Export-ModuleMember -Function Log
Export-ModuleMember -Function Log,IsAdmin
View File
View File
View File
@@ -1,6 +1,4 @@
Function global:Remediation-StopProcess
{
param([string]$Name,[switch]$Force=$false)
param([string]$Name,[switch]$Force=$false)
If ( $Name )
{
@@ -31,7 +29,4 @@ If ( $Name )
Else { Write-Output "No running processes match the name ${Name}" }
}
Else { Write-Output "No process name was specified!" }
}
Export-ModuleMember -Function Remediation-StopProcess
Else { Write-Output "No process name was specified!" }
@@ -1,6 +1,4 @@
Function global:Remove-DeltekVision
{
## Stop the DeltekVision process
## Stop the DeltekVision process
Remediation-StopProcess -Name "DeltekVision" -Force
## Set the path to Deltek Vision
@@ -13,7 +11,4 @@ If ( Test-Path $APP_PATH )
Try { Remove-Item $APP_PATH -Recurse -Force }
Catch { Write-Output $_.Exception.Message }
} Else { Write-Output "${APP_PATH} does not exist!" }
}
Export-ModuleMember -Function Remove-DeltekVision
} Else { Write-Output "${APP_PATH} does not exist!" }
+7 -6
View File
@@ -1,14 +1,15 @@
## Make sure the computer is running Windows 10
If ( ([System.Environment]::OSVersion.Version).Major -ge 10 ) {
## Make sure the endpoint isn't already running 1909
If ( ([System.Environment]::OSVersion.Version).Build -lt 18363 ) {
## Make sure the endpoint isn't already running 2004
If ( ([System.Environment]::OSVersion.Version).Build -lt 19041 ) {
## Set the directory where the Windows Update Assistant will be downloaded to
$DOWNLOADS = "${Env:TEMP}"
## URL to the 1909 version of the Windows Update Assistant
$URL = 'https://download.microsoft.com/download/9/b/f/9bf08afb-bfd8-488a-9ce6-90134cea4d8f/Windows10Upgrade9252.exe'
## URL to the 2004 version of the Windows Update Assistant
## If $URL is already defined when the script is run, just use that value
If ( !($URL) ) { $URL = 'https://download.microsoft.com/download/8/3/c/83c39dca-2d27-4c24-b98b-0a4d6d921c80/Windows10Upgrade9252.exe' }
## Uninstall previous Windows 10 Update Assistant
If ( Test-Path "${Env:SystemDrive}\Windows10Upgrade\Windows10UpgraderApp.exe" )
@@ -48,6 +49,6 @@ If ( ([System.Environment]::OSVersion.Version).Major -ge 10 ) {
Remove-Item "${DOWNLOADS}\${FILENAME}"
}
} Else { Write-Host "This endpoint is already up to date." }
} Else { Write-Output "This endpoint is already up to date." }
} Else { Write-Host "This endpoint is not running Windows 10." }
} Else { Write-Output "This endpoint is not running Windows 10." }
@@ -35,7 +35,7 @@ Else
}
## Kill all running instances of TeamViewer
Get-Process | Where { $_.Name -like "*TeamViewer*" }
Get-Process | Where { $_.Name -like "*TeamViewer*" } | Stop-Process
If ( Test-Path "${INSTALLDIR}\uninstall.exe" )
{ Start-Process "${INSTALLDIR}\uninstall.exe" -ArgumentList "/S" -Wait }
+1
View File
@@ -0,0 +1 @@
Write-Host "It works!"