too many updates
This commit is contained in:
@@ -270,10 +270,21 @@ Function IsWindowsBuild {
|
|||||||
Function Get-TempPath { Return [System.IO.Path]::GetTempPath() }
|
Function Get-TempPath { Return [System.IO.Path]::GetTempPath() }
|
||||||
|
|
||||||
# Get a random file name with random extension
|
# 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
|
# Create a new temp file in the current TEMP folder
|
||||||
Function Get-RandomTempFile { Return [System.IO.Path]::Combine($(Get-TempPath), $(Get-RandomFile)) }
|
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
|
# Determine if the system is 64-bit or not
|
||||||
Function Is64bit {
|
Function Is64bit {
|
||||||
@@ -449,7 +460,7 @@ Function End-Process
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Create-Shortcut {
|
Function New-Shortcut {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)][string]$Path,
|
[Parameter(Mandatory=$true)][string]$Path,
|
||||||
[Parameter(Mandatory=$true)][string]$TargetPath,
|
[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" }
|
Else { Write-Output "Cannot create shortcut because the target path does not exist" }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to enable or disable a specified log
|
# Enable a Windows Event Log
|
||||||
Function Toggle-Log {
|
Function Enable-Log {
|
||||||
param (
|
param ([Parameter(Mandatory = $true,ValueFromPipeline=$true)][string]$Name)
|
||||||
[Parameter(Mandatory = $true)][string]$Name,
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Enable')][switch]$Enable,
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Disable')][switch]$Disable
|
|
||||||
)
|
|
||||||
Try {
|
Try {
|
||||||
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $Name
|
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $Name
|
||||||
If ( $Enable ) { Write-Output "Enabing ${Name} event log" ; $log.IsEnabled = $true }
|
Write-Output "Enabing ${Name} event log"
|
||||||
If ( $Disable ) { Write-Output "Disabing ${Name} event log" ; $log.IsEnabled = $false }
|
$log.IsEnabled = $true
|
||||||
$log.SaveChanges()
|
$log.SaveChanges()
|
||||||
}
|
}
|
||||||
Catch { Write-Output $_.Exception.Message }
|
Catch { Write-Error $_.Exception.Message }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install the PSAtera Powershell module
|
# Disable a Windows Event Log
|
||||||
Function Install-PSAteraModule {
|
Function Disable-Log {
|
||||||
|
param ([Parameter(Mandatory = $true,ValueFromPipeline=$true)][string]$Name)
|
||||||
Try {
|
Try {
|
||||||
$module = Get-Module -ListAvailable -Name PSAtera
|
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $Name
|
||||||
If ( (-not $module) -and (IsAdmin) ) {
|
Write-Output "Disabing ${Name} event log"
|
||||||
Write-Output "Installing PSAtera Powershell module"
|
$log.IsEnabled = $false
|
||||||
Install-Module -Name PSAtera -Force
|
$log.SaveChanges()
|
||||||
}
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Catch { Write-Error $_.Exception.Message }
|
Catch { Write-Error $_.Exception.Message }
|
||||||
}
|
}
|
||||||
@@ -527,51 +531,58 @@ Function Install-MSP360Module {
|
|||||||
Catch { Write-Error $_.Exception.Message }
|
Catch { Write-Error $_.Exception.Message }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to delete a file
|
# Function to ZIP a file or directory, returns the newly created zip file
|
||||||
Function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
|
Function Compress-Archive {
|
||||||
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 {
|
|
||||||
param(
|
param(
|
||||||
[Parameter(ValueFromPipeline=$true)][string]$path,
|
[Parameter(ValueFromPipeline=$true)][string]$Path,
|
||||||
[Parameter(ValueFromPipeline=$false)][string]$dest
|
[Parameter(ValueFromPipeline=$false)][string]$DestinationPath,
|
||||||
|
[Parameter(ValueFromPipeline=$false)][switch]$Force=$false
|
||||||
)
|
)
|
||||||
If ( $(Get-Item $path) -is [System.IO.DirectoryInfo] ) {
|
BEGIN {
|
||||||
If ( [string]::IsNullOrEmpty($dest) ) { $dest = '{0}\{1}.zip' -f $(Split-Path -Parent $path),$(Split-Path -Leaf $path) }
|
If ( ($Force) -and (Test-Path $DestinationPath) ) {
|
||||||
Write-Output "Creating zip file of: ${path}"
|
Write-Output "Deleting existing archive: ""${DestinationPath}"""
|
||||||
Try {
|
Remove-Item -Path $DestinationPath -Force -ErrorAction Stop
|
||||||
Add-Type -Assembly "System.IO.Compression.FileSystem"
|
|
||||||
[IO.Compression.ZipFile]::CreateFromDirectory($path, $dest)
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
Catch { Write-Error $_.Exception.Message }
|
|
||||||
Zip-Object $dir
|
|
||||||
}
|
}
|
||||||
Else { Write-Output "Could not determine the file/folder status: ${path}" }
|
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"
|
||||||
|
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 }
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
If ( !$CreateNewArchive ) { Write-Output "Finished updating existing archive: ""${DestinationPath}""" }
|
||||||
|
If ( Test-Path $DestinationPath ) { Return Get-Item -Path $DestinationPath } Else { Return $null }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to UNZIP a file or directory
|
# 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" ) {
|
If ( [System.IO.Path]::GetExtension($path) -eq ".zip" ) {
|
||||||
$dest = Split-Path -Parent $path
|
$dest = Split-Path -Parent $path
|
||||||
Write-Output "Extracting ""${path}"" to ""${dest}"""
|
Write-Output "Extracting ""${path}"" to ""${dest}"""
|
||||||
@@ -601,7 +612,7 @@ Function Get-LiquidFilesCLI {
|
|||||||
Catch { Write-Error $_.Exception.Message }
|
Catch { Write-Error $_.Exception.Message }
|
||||||
}
|
}
|
||||||
Download-File -URL $url -File $zip_path | Out-Null
|
Download-File -URL $url -File $zip_path | Out-Null
|
||||||
Unzip-Object $zip_path
|
Expand-Archive $zip_path
|
||||||
Return $exe_path
|
Return $exe_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user