From cb110b354d75a2ab56bb1c2c2c9c8a7970022893 Mon Sep 17 00:00:00 2001 From: dyoder Date: Tue, 18 Aug 2020 16:20:20 -0400 Subject: [PATCH] update --- Cleanup-AppXTempFiles.ps1 | 9 ++ Cleanup-LogFiles.ps1 | 2 + Cleanup-SystemPath.ps1 | 24 +++++ Cleanup-TempFiles.ps1 | 13 +++ Deploy-PSModule.ps1 | 29 +++--- Fix-SystemPrintQueue.ps1 | 22 +++++ Fix-WindowsScriptingComponents.ps1 | 36 ++++++++ Fix-WindowsUpdate.ps1 | 21 +++++ PSModule/PSModule-Cleanup.psm1 | 63 ------------- PSModule/PSModule-Fix.psm1 | 90 ------------------- ...le-Set.psm1 => PSModule-SetWinEvtLog.psm1} | 2 +- PSModule/PSModule.psm1 | 81 ++++++++++++++--- .../PSModule-Cleanup.psm1} | 0 .../PSModule-Create.psm1} | 0 .../PSModule-Fix.psm1} | 0 .../PSModule-Get.psm1} | 0 .../PSModule-Install.psm1} | 0 PSModule/old/PSModule-Remediation.psm1 | 0 PSModule/old/PSModule-Remove.psm1 | 0 PSModule/old/PSModule-Start.psm1 | 0 PSModule/old/PSModule-Upload.psm1 | 0 ...iation.psm1 => Remediation-StopProcess.ps1 | 9 +- ...ule-Remove.psm1 => Remove-DeltekVision.ps1 | 9 +- Start-Windows10UpdateAssistant.ps1 | 13 +-- ...TeamViewer.ps1 => Uninstall-TeamViewer.ps1 | 2 +- test.ps1 | 1 + 26 files changed, 225 insertions(+), 201 deletions(-) create mode 100644 Cleanup-AppXTempFiles.ps1 create mode 100644 Cleanup-LogFiles.ps1 create mode 100644 Cleanup-SystemPath.ps1 create mode 100644 Cleanup-TempFiles.ps1 create mode 100644 Fix-SystemPrintQueue.ps1 create mode 100644 Fix-WindowsScriptingComponents.ps1 create mode 100644 Fix-WindowsUpdate.ps1 delete mode 100644 PSModule/PSModule-Cleanup.psm1 delete mode 100644 PSModule/PSModule-Fix.psm1 rename PSModule/{PSModule-Set.psm1 => PSModule-SetWinEvtLog.psm1} (98%) rename PSModule/{PSModule-Create.psm1 => old/PSModule-Cleanup.psm1} (100%) rename PSModule/{PSModule-Get.psm1 => old/PSModule-Create.psm1} (100%) rename PSModule/{PSModule-Install.psm1 => old/PSModule-Fix.psm1} (100%) rename PSModule/{PSModule-Start.psm1 => old/PSModule-Get.psm1} (100%) rename PSModule/{PSModule-Upload.psm1 => old/PSModule-Install.psm1} (100%) create mode 100644 PSModule/old/PSModule-Remediation.psm1 create mode 100644 PSModule/old/PSModule-Remove.psm1 create mode 100644 PSModule/old/PSModule-Start.psm1 create mode 100644 PSModule/old/PSModule-Upload.psm1 rename PSModule/PSModule-Remediation.psm1 => Remediation-StopProcess.ps1 (81%) rename PSModule/PSModule-Remove.psm1 => Remove-DeltekVision.ps1 (68%) rename Remove-TeamViewer.ps1 => Uninstall-TeamViewer.ps1 (96%) create mode 100644 test.ps1 diff --git a/Cleanup-AppXTempFiles.ps1 b/Cleanup-AppXTempFiles.ps1 new file mode 100644 index 0000000..39f3382 --- /dev/null +++ b/Cleanup-AppXTempFiles.ps1 @@ -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 +} \ No newline at end of file diff --git a/Cleanup-LogFiles.ps1 b/Cleanup-LogFiles.ps1 new file mode 100644 index 0000000..c439a20 --- /dev/null +++ b/Cleanup-LogFiles.ps1 @@ -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 \ No newline at end of file diff --git a/Cleanup-SystemPath.ps1 b/Cleanup-SystemPath.ps1 new file mode 100644 index 0000000..c7eab07 --- /dev/null +++ b/Cleanup-SystemPath.ps1 @@ -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 \ No newline at end of file diff --git a/Cleanup-TempFiles.ps1 b/Cleanup-TempFiles.ps1 new file mode 100644 index 0000000..e049380 --- /dev/null +++ b/Cleanup-TempFiles.ps1 @@ -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 } + +} \ No newline at end of file diff --git a/Deploy-PSModule.ps1 b/Deploy-PSModule.ps1 index 42bc04c..79dffd0 100644 --- a/Deploy-PSModule.ps1 +++ b/Deploy-PSModule.ps1 @@ -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 } diff --git a/Fix-SystemPrintQueue.ps1 b/Fix-SystemPrintQueue.ps1 new file mode 100644 index 0000000..98fbe95 --- /dev/null +++ b/Fix-SystemPrintQueue.ps1 @@ -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." } \ No newline at end of file diff --git a/Fix-WindowsScriptingComponents.ps1 b/Fix-WindowsScriptingComponents.ps1 new file mode 100644 index 0000000..bc46c67 --- /dev/null +++ b/Fix-WindowsScriptingComponents.ps1 @@ -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 + } +} \ No newline at end of file diff --git a/Fix-WindowsUpdate.ps1 b/Fix-WindowsUpdate.ps1 new file mode 100644 index 0000000..a9dd859 --- /dev/null +++ b/Fix-WindowsUpdate.ps1 @@ -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" } \ No newline at end of file diff --git a/PSModule/PSModule-Cleanup.psm1 b/PSModule/PSModule-Cleanup.psm1 deleted file mode 100644 index 2eda36b..0000000 --- a/PSModule/PSModule-Cleanup.psm1 +++ /dev/null @@ -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 } - -} -} \ No newline at end of file diff --git a/PSModule/PSModule-Fix.psm1 b/PSModule/PSModule-Fix.psm1 deleted file mode 100644 index 203f6ea..0000000 --- a/PSModule/PSModule-Fix.psm1 +++ /dev/null @@ -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" } -} \ No newline at end of file diff --git a/PSModule/PSModule-Set.psm1 b/PSModule/PSModule-SetWinEvtLog.psm1 similarity index 98% rename from PSModule/PSModule-Set.psm1 rename to PSModule/PSModule-SetWinEvtLog.psm1 index e369091..96121b4 100644 --- a/PSModule/PSModule-Set.psm1 +++ b/PSModule/PSModule-SetWinEvtLog.psm1 @@ -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) ) { diff --git a/PSModule/PSModule.psm1 b/PSModule/PSModule.psm1 index c7cebca..d81f6d0 100644 --- a/PSModule/PSModule.psm1 +++ b/PSModule/PSModule.psm1 @@ -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 \ No newline at end of file +Export-ModuleMember -Function Log,IsAdmin \ No newline at end of file diff --git a/PSModule/PSModule-Create.psm1 b/PSModule/old/PSModule-Cleanup.psm1 similarity index 100% rename from PSModule/PSModule-Create.psm1 rename to PSModule/old/PSModule-Cleanup.psm1 diff --git a/PSModule/PSModule-Get.psm1 b/PSModule/old/PSModule-Create.psm1 similarity index 100% rename from PSModule/PSModule-Get.psm1 rename to PSModule/old/PSModule-Create.psm1 diff --git a/PSModule/PSModule-Install.psm1 b/PSModule/old/PSModule-Fix.psm1 similarity index 100% rename from PSModule/PSModule-Install.psm1 rename to PSModule/old/PSModule-Fix.psm1 diff --git a/PSModule/PSModule-Start.psm1 b/PSModule/old/PSModule-Get.psm1 similarity index 100% rename from PSModule/PSModule-Start.psm1 rename to PSModule/old/PSModule-Get.psm1 diff --git a/PSModule/PSModule-Upload.psm1 b/PSModule/old/PSModule-Install.psm1 similarity index 100% rename from PSModule/PSModule-Upload.psm1 rename to PSModule/old/PSModule-Install.psm1 diff --git a/PSModule/old/PSModule-Remediation.psm1 b/PSModule/old/PSModule-Remediation.psm1 new file mode 100644 index 0000000..e69de29 diff --git a/PSModule/old/PSModule-Remove.psm1 b/PSModule/old/PSModule-Remove.psm1 new file mode 100644 index 0000000..e69de29 diff --git a/PSModule/old/PSModule-Start.psm1 b/PSModule/old/PSModule-Start.psm1 new file mode 100644 index 0000000..e69de29 diff --git a/PSModule/old/PSModule-Upload.psm1 b/PSModule/old/PSModule-Upload.psm1 new file mode 100644 index 0000000..e69de29 diff --git a/PSModule/PSModule-Remediation.psm1 b/Remediation-StopProcess.ps1 similarity index 81% rename from PSModule/PSModule-Remediation.psm1 rename to Remediation-StopProcess.ps1 index f20ca2b..a0a7c75 100644 --- a/PSModule/PSModule-Remediation.psm1 +++ b/Remediation-StopProcess.ps1 @@ -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 \ No newline at end of file +Else { Write-Output "No process name was specified!" } \ No newline at end of file diff --git a/PSModule/PSModule-Remove.psm1 b/Remove-DeltekVision.ps1 similarity index 68% rename from PSModule/PSModule-Remove.psm1 rename to Remove-DeltekVision.ps1 index c492778..ca8c585 100644 --- a/PSModule/PSModule-Remove.psm1 +++ b/Remove-DeltekVision.ps1 @@ -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!" } \ No newline at end of file diff --git a/Start-Windows10UpdateAssistant.ps1 b/Start-Windows10UpdateAssistant.ps1 index 8b4a82c..f29fc30 100644 --- a/Start-Windows10UpdateAssistant.ps1 +++ b/Start-Windows10UpdateAssistant.ps1 @@ -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." } diff --git a/Remove-TeamViewer.ps1 b/Uninstall-TeamViewer.ps1 similarity index 96% rename from Remove-TeamViewer.ps1 rename to Uninstall-TeamViewer.ps1 index b443474..aad0a9f 100644 --- a/Remove-TeamViewer.ps1 +++ b/Uninstall-TeamViewer.ps1 @@ -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 } diff --git a/test.ps1 b/test.ps1 new file mode 100644 index 0000000..47fc247 --- /dev/null +++ b/test.ps1 @@ -0,0 +1 @@ +Write-Host "It works!" \ No newline at end of file