Compare commits

...
4 Commits
Author SHA1 Message Date
dyoder 8fa1f1ef61 adjusted for removal of Remove-File cmdlet 2023-10-06 14:16:19 -04:00
dyoder 7f98291e12 update to use new funcs 2023-10-06 13:04:29 -04:00
dyoder 4cc7e91722 too many updates 2023-10-06 13:04:09 -04:00
dyoder cfa87fc674 removed for later rework 2023-10-05 17:04:53 -04:00
9 changed files with 100 additions and 118 deletions
+15
View File
@@ -0,0 +1,15 @@
$LogsToEnable = @(
''
)
$LogsToDisable = @(
''
)
ForEach ( $log in $LogsToEnable ) {
Enable-Log -Name $log
}
ForEach ( $log in $LogsToDisable) {
Disable-Log -Name $log
}
+3 -2
View File
@@ -28,5 +28,6 @@ Try { Set-MBSAgentSetting -Edition $AgentEdition -Verbose }
Catch { Write-Error $_.Exception.Message }
# Delete the desktop icon
"${Env:PUBLIC}\Desktop\Emberkom Backup.LNK",
"${Env:PUBLIC}\Desktop\Emberkom Cloud Backup.LNK" | Remove-File
Write-Output "Removing desktop icon"
Remove-Item -Path "${Env:PUBLIC}\Desktop\Emberkom Backup.LNK" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "${Env:PUBLIC}\Desktop\Emberkom Cloud Backup.LNK" -Force -ErrorAction SilentlyContinue
+1 -1
View File
@@ -1,5 +1,5 @@
# Run SFC to check the filesystem, convert the result from Unicode to UTF8, delete the intermediate $tempFile
$tempFile = Get-RandomTempFile
$tempFile = New-TemporaryFile
$(sfc.exe /scannow) | Out-File $tempFile
Set-Content -Path $tempFile -Value $(Get-Content -Path $tempFile -Encoding Unicode) -Encoding UTF8
$SFCOutput = Get-Content -Path $tempFile
+1 -1
View File
@@ -29,7 +29,7 @@ If ( -not (Test-Path $SHORTCUT_PATH) ) {
If ( $BROWSER_PATH ) {
Write-Output "Installing Deltek Vision for ${APP_NAME}"
Create-Shortcut -Path "${Env:Public}\Desktop\Deltek Vision.lnk" -TargetPath $BROWSER_PATH -Arguments $VisionURL -Description "Launch Deltek Vision"
New-Shortcut -Path "${Env:Public}\Desktop\Deltek Vision.lnk" -TargetPath $BROWSER_PATH -Arguments $VisionURL -Description "Launch Deltek Vision"
}
Else { Write-Output "A compatible browser could not be found: ${BROWSER_PATH}" }
}
+3 -2
View File
@@ -42,5 +42,6 @@ Try { Set-MBSAgentSetting -Edition $AgentEdition -Verbose }
Catch { Write-Error $_.Exception.Message }
# Delete the desktop icon
"${Env:PUBLIC}\Desktop\Emberkom Backup.LNK",
"${Env:PUBLIC}\Desktop\Emberkom Cloud Backup.LNK" | Remove-File
Write-Output "Removing desktop icon"
Remove-Item -Path "${Env:PUBLIC}\Desktop\Emberkom Backup.LNK" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "${Env:PUBLIC}\Desktop\Emberkom Cloud Backup.LNK" -Force -ErrorAction SilentlyContinue
+1 -1
View File
@@ -22,7 +22,7 @@ If ( IsAdmin )
## Create shortcut on Public desktop
If ( $CreateDesktopShortcut ) {
Create-Shortcut -Path "${Env:Public}\Desktop\WireGuard VPN.LNK" -TargetPath "${Env:ProgramFiles}\WireGuard\wireguard.exe" -Description "WireGuard: Fast, Modern, Secure VPN Tunnel"
New-Shortcut -Path "${Env:Public}\Desktop\WireGuard VPN.LNK" -TargetPath "${Env:ProgramFiles}\WireGuard\wireguard.exe" -Description "WireGuard: Fast, Modern, Secure VPN Tunnel"
}
}
Else { Write-Output "Must be an administrator to install WireGuard" }
-7
View File
@@ -1,7 +0,0 @@
$LogsToEnable = @(
''
)
ForEach ( $log in $LogsToEnable ) {
Toggle-Log -Name $log -Enable
}
+70 -59
View File
@@ -270,10 +270,21 @@ Function IsWindowsBuild {
Function Get-TempPath { Return [System.IO.Path]::GetTempPath() }
# Get a random file name with random extension
Function Get-RandomFile { Return [System.IO.Path]::GetRandomFileName() }
Function Get-RandomFileName { Return [System.IO.Path]::GetRandomFileName() }
# Get a random temp file in the current TEMP folder
Function Get-RandomTempFile { Return [System.IO.Path]::Combine($(Get-TempPath), $(Get-RandomFile)) }
# Create a new temp file in the current TEMP folder
Function New-TemporaryFile {
$file = [System.IO.Path]::Combine($(Get-TempPath), $(Get-RandomFileName))
New-Item -Path $file -ItemType File -Force -ErrorAction SilentlyContinue | Out-Null
Return Get-Item -Path $file
}
# Create a new temp directory in the current TEMP folder
Function New-TemporaryDirectory {
$directory = [System.IO.Path]::Combine($(Get-TempPath), $(Get-RandomFileName))
New-Item -Path $directory -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
Return Get-Item -Path $directory
}
# Determine if the system is 64-bit or not
Function Is64bit {
@@ -449,7 +460,7 @@ Function End-Process
}
}
Function Create-Shortcut {
Function New-Shortcut {
param(
[Parameter(Mandatory=$true)][string]$Path,
[Parameter(Mandatory=$true)][string]$TargetPath,
@@ -480,33 +491,26 @@ Function Create-Shortcut {
Else { Write-Output "Cannot create shortcut because the target path does not exist" }
}
# Function to enable or disable a specified log
Function Toggle-Log {
param (
[Parameter(Mandatory = $true)][string]$Name,
[Parameter(Mandatory = $true, ParameterSetName = 'Enable')][switch]$Enable,
[Parameter(Mandatory = $true, ParameterSetName = 'Disable')][switch]$Disable
)
# Enable a Windows Event Log
Function Enable-Log {
param ([Parameter(Mandatory = $true,ValueFromPipeline=$true)][string]$Name)
Try {
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $Name
If ( $Enable ) { Write-Output "Enabing ${Name} event log" ; $log.IsEnabled = $true }
If ( $Disable ) { Write-Output "Disabing ${Name} event log" ; $log.IsEnabled = $false }
Write-Output "Enabing ${Name} event log"
$log.IsEnabled = $true
$log.SaveChanges()
}
Catch { Write-Output $_.Exception.Message }
Catch { Write-Error $_.Exception.Message }
}
# Function to install the PSAtera Powershell module
Function Install-PSAteraModule {
# Disable a Windows Event Log
Function Disable-Log {
param ([Parameter(Mandatory = $true,ValueFromPipeline=$true)][string]$Name)
Try {
$module = Get-Module -ListAvailable -Name PSAtera
If ( (-not $module) -and (IsAdmin) ) {
Write-Output "Installing PSAtera Powershell module"
Install-Module -Name PSAtera -Force
}
ElseIf ( (-not $module) -and (-not (IsAdmin)) ) {
Write-Output "The PSAtera module needs to be installed, but the current security context is not sufficient to install it"
}
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $Name
Write-Output "Disabing ${Name} event log"
$log.IsEnabled = $false
$log.SaveChanges()
}
Catch { Write-Error $_.Exception.Message }
}
@@ -527,51 +531,58 @@ Function Install-MSP360Module {
Catch { Write-Error $_.Exception.Message }
}
# Function to delete a file
Function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
If ( Test-Path $path ) {
If ( !((Get-Item $path) -is [System.IO.DirectoryInfo]) ) {
Try {
Write-Output "Delete ""${path}"""
Remove-Item $path -Force
}
Catch { Write-Error $_.Exception.Message }
}
}
}
# Function to ZIP a file or directory
Function Zip-Object {
# Function to ZIP a file or directory, returns the newly created zip file
Function Compress-Archive {
param(
[Parameter(ValueFromPipeline=$true)][string]$path,
[Parameter(ValueFromPipeline=$false)][string]$dest
[Parameter(ValueFromPipeline=$true)][string]$Path,
[Parameter(ValueFromPipeline=$false)][string]$DestinationPath,
[Parameter(ValueFromPipeline=$false)][switch]$Force=$false
)
If ( $(Get-Item $path) -is [System.IO.DirectoryInfo] ) {
If ( [string]::IsNullOrEmpty($dest) ) { $dest = '{0}\{1}.zip' -f $(Split-Path -Parent $path),$(Split-Path -Leaf $path) }
Write-Output "Creating zip file of: ${path}"
BEGIN {
If ( ($Force) -and (Test-Path $DestinationPath) ) {
Write-Output "Deleting existing archive: ""${DestinationPath}"""
Remove-Item -Path $DestinationPath -Force -ErrorAction Stop
}
}
PROCESS {
If ( !($Force) -and (Test-Path $DestinationPath) ) { $CreateNewArchive = $false } Else { $CreateNewArchive = $true }
Try {
Add-Type -Assembly "System.IO.Compression"
Add-Type -Assembly "System.IO.Compression.FileSystem"
[IO.Compression.ZipFile]::CreateFromDirectory($path, $dest)
Switch ( $(Get-Item -Path $Path) ) {
{$_ -is [System.IO.DirectoryInfo]} {
If ( $CreateNewArchive ) {
Write-Output "Creating new zip archive: ""${DestinationPath}"""
[System.IO.Compression.ZipFile]::CreateFromDirectory($Path, $DestinationPath, [System.IO.Compression.CompressionLevel]::Optimal, $true)
} Else {
If ( (Get-Command Microsoft.Powershell.Archive\Compress-Archive -ErrorAction SilentlyContinue) ) {
Microsoft.Powershell.Archive\Compress-Archive -Path $Path -DestinationPath $DestinationPath -Update -CompressionLevel Optimal
} Else {
Write-Error "Updating an existing zip archive with a folder structure is not currently supported"
}
}
}
{$_ -is [System.IO.FileInfo]} {
If ( $CreateNewArchive ) {
Write-Output "Creating new zip archive: ""${DestinationPath}"""
$ArchiveMode = [System.IO.Compression.ZipArchiveMode]::Create
} Else { $ArchiveMode = [System.IO.Compression.ZipArchiveMode]::Update }
[System.IO.Compression.ZipArchive]$DestinationArchive = [System.IO.Compression.ZipFile]::Open($DestinationPath, $ArchiveMode)
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($DestinationArchive, $Path, (Split-Path $Path -Leaf)) | Out-Null
$DestinationArchive.Dispose()
}
}
}
Catch { Write-Error $_.Exception.Message }
If ( Test-Path $dest ) { Return $dest } Else { Return $false }
}
ElseIf ( $(Get-Item $path) -is [System.IO.FileInfo] ) {
$dir = $path.Substring(0, $path.LastIndexOf('.'))
Try {
Write-Output "Creating directory: ${path}"
New-Item -ItemType Directory -Path $dir -ErrorAction Stop | Out-Null
Write-Output "Moving ""${path}"" into ""${dir}"""
Move-Item -Path $path -Destination $dir -Force -ErrorAction Stop | Out-Null
END {
If ( !$CreateNewArchive ) { Write-Output "Finished updating existing archive: ""${DestinationPath}""" }
If ( Test-Path $DestinationPath ) { Return Get-Item -Path $DestinationPath } Else { Return $null }
}
Catch { Write-Error $_.Exception.Message }
Zip-Object $dir
}
Else { Write-Output "Could not determine the file/folder status: ${path}" }
}
# Function to UNZIP a file or directory
Function Unzip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) {
Function Expand-Archive ([Parameter(ValueFromPipeline=$true)][string]$path) {
If ( [System.IO.Path]::GetExtension($path) -eq ".zip" ) {
$dest = Split-Path -Parent $path
Write-Output "Extracting ""${path}"" to ""${dest}"""
@@ -601,7 +612,7 @@ Function Get-LiquidFilesCLI {
Catch { Write-Error $_.Exception.Message }
}
Download-File -URL $url -File $zip_path | Out-Null
Unzip-Object $zip_path
Expand-Archive $zip_path
Return $exe_path
}
-39
View File
@@ -1,39 +0,0 @@
If ( $LFCLI ) {
## Create the path to $FileToUpload and zip the specified directory if necessary
If ( $(Get-Item $DataToUpload) -is [System.IO.DirectoryInfo] ) {
$FileToUpload = '{0}\{1}.zip' -f $Global:OutputDirectory,$(Split-Path -Leaf $DataToUpload)
Zip-Object -path $DataToUpload -dest $FileToUpload
$DeleteAfterUpload = $true
}
Else {
$FileToUpload = $DataToUpload
$DeleteAfterUpload = $false
}
Install-PSAteraModule
Import-Module -Name PSAtera
Set-AteraAPIKey -APIKey $AteraAPIKey
$LFHost = $(Get-AteraCustomValue -ObjectType Customer -ObjectId 9 -FieldName 'LiquidFiles Host URL').ValueAsString
$FiledropURL = "${LFHost}/filedrop/cmd"
## Set the message properties for the file upload
$From = '{0}@{1}.net' -f $Env:COMPUTERNAME,$($Global:MSPName -replace " ","").ToLower()
$Subject = [System.IO.Path]::GetFileNameWithoutExtension($FileToUpload)
$Message = ""
If ( Test-Path $FileToUpload ) {
Write-Output "Uploading ""${FileToUpload}"""
If ( $DeleteAfterUpload ) {
Try { Start-Process "${LFCLI}" -ArgumentList "filedrop /url:${FiledropURL} /from:""${From}"" /subject:""${Subject}"" /msg:""${Message}"" /c:n /deleteAfterUpload /f:""${FileToUpload}""" -Wait }
Catch { Write-Error $_.Exception.Message }
}
Else {
Try { Start-Process "${LFCLI}" -ArgumentList "filedrop /url:${FiledropURL} /from:""${From}"" /subject:""${Subject}"" /msg:""${Message}"" /c:n /f:""${FileToUpload}""" -Wait }
Catch { Write-Error $_.Exception.Message }
}
}
Else { Write-Output "The specified file does not exist: ""${FileToUpload}""" }
}
Else { Write-Output "Could not upload any data because the LiquidFiles CLI tool was not found" }