uppercase function keyword
add function Beautify-Bytes
This commit is contained in:
@@ -479,7 +479,7 @@ Function Create-Shortcut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to enable or disable a specified log
|
# Function to enable or disable a specified log
|
||||||
function Toggle-Log {
|
Function Toggle-Log {
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)][string]$Name,
|
[Parameter(Mandatory = $true)][string]$Name,
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Enable')][switch]$Enable,
|
[Parameter(Mandatory = $true, ParameterSetName = 'Enable')][switch]$Enable,
|
||||||
@@ -495,7 +495,7 @@ function Toggle-Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to install the PSAtera Powershell module
|
# Function to install the PSAtera Powershell module
|
||||||
function Install-PSAteraModule {
|
Function Install-PSAteraModule {
|
||||||
Try {
|
Try {
|
||||||
$module = Get-Module -ListAvailable -Name PSAtera
|
$module = Get-Module -ListAvailable -Name PSAtera
|
||||||
If ( (-not $module) -and (IsAdmin) ) {
|
If ( (-not $module) -and (IsAdmin) ) {
|
||||||
@@ -510,7 +510,7 @@ function Install-PSAteraModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to install the MSP360 Powershell module
|
# Function to install the MSP360 Powershell module
|
||||||
function Install-MSP360Module {
|
Function Install-MSP360Module {
|
||||||
Try {
|
Try {
|
||||||
$module = Get-Module -ListAvailable -Name MSP360
|
$module = Get-Module -ListAvailable -Name MSP360
|
||||||
If ( (-not $module) -and (IsAdmin) ) {
|
If ( (-not $module) -and (IsAdmin) ) {
|
||||||
@@ -526,7 +526,7 @@ function Install-MSP360Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to delete a file
|
# Function to delete a file
|
||||||
function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
|
Function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
|
||||||
If ( Test-Path $path ) {
|
If ( Test-Path $path ) {
|
||||||
If ( !((Get-Item $path) -is [System.IO.DirectoryInfo]) ) {
|
If ( !((Get-Item $path) -is [System.IO.DirectoryInfo]) ) {
|
||||||
Try {
|
Try {
|
||||||
@@ -539,7 +539,7 @@ function Remove-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to ZIP a file or directory
|
# Function to ZIP a file or directory
|
||||||
function Zip-Object {
|
Function Zip-Object {
|
||||||
param(
|
param(
|
||||||
[Parameter(ValueFromPipeline=$true)][string]$path,
|
[Parameter(ValueFromPipeline=$true)][string]$path,
|
||||||
[Parameter(ValueFromPipeline=$false)][string]$dest
|
[Parameter(ValueFromPipeline=$false)][string]$dest
|
||||||
@@ -569,7 +569,7 @@ function Zip-Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to UNZIP a file or directory
|
# Function to UNZIP a file or directory
|
||||||
function Unzip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) {
|
Function Unzip-Object ([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
|
||||||
LogMsg "Extracting ""${path}"" to ""${dest}"""
|
LogMsg "Extracting ""${path}"" to ""${dest}"""
|
||||||
@@ -583,7 +583,7 @@ function Unzip-Object ([Parameter(ValueFromPipeline=$true)][string]$path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to get a copy of the LiquidFiles CLI agent
|
# Function to get a copy of the LiquidFiles CLI agent
|
||||||
function Get-LiquidFilesCLI {
|
Function Get-LiquidFilesCLI {
|
||||||
$url = 'https://lfupdate.s3.amazonaws.com/clients/windows_cli/LiquidFilesCLI-2.0.128.zip'
|
$url = 'https://lfupdate.s3.amazonaws.com/clients/windows_cli/LiquidFilesCLI-2.0.128.zip'
|
||||||
$zip_filename = Split-Path -Leaf $url
|
$zip_filename = Split-Path -Leaf $url
|
||||||
$zip_path = "${Global:ToolsDirectory}\${zip_filename}"
|
$zip_path = "${Global:ToolsDirectory}\${zip_filename}"
|
||||||
@@ -604,13 +604,13 @@ function Get-LiquidFilesCLI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to determine if an app is running
|
# Function to determine if an app is running
|
||||||
function IsRunning ([Parameter(ValueFromPipeline=$true)][string]$Name) {
|
Function IsRunning ([Parameter(ValueFromPipeline=$true)][string]$Name) {
|
||||||
$RunningInstances = Get-Process | Where-Object { $_.Name -ilike $Name }
|
$RunningInstances = Get-Process | Where-Object { $_.Name -ilike $Name }
|
||||||
If ( $RunningInstances ) { Return $true } Else { Return $false }
|
If ( $RunningInstances ) { Return $true } Else { Return $false }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to create a local user account
|
# Function to create a local user account
|
||||||
function Create-LocalUser {
|
Function Create-LocalUser {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)][string]$Username,
|
[Parameter(Mandatory=$true)][string]$Username,
|
||||||
[Parameter(Mandatory=$true)][string]$Password,
|
[Parameter(Mandatory=$true)][string]$Password,
|
||||||
@@ -657,12 +657,12 @@ function Create-LocalUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Returns the number of MB a process is consuming
|
# Returns the number of MB a process is consuming
|
||||||
function Get-MemoryUsage ([string]$AppName) {
|
Function Get-MemoryUsage ([string]$AppName) {
|
||||||
[math]::Round((Get-Process -Name $AppName -ErrorAction SilentlyContinue | Measure-Object -Property WorkingSet -Sum).Sum / 1MB)
|
[math]::Round((Get-Process -Name $AppName -ErrorAction SilentlyContinue | Measure-Object -Property WorkingSet -Sum).Sum / 1MB)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Kills a process if it's using more than the specified amount of memory
|
# Kills a process if it's using more than the specified amount of memory
|
||||||
function Stop-MemoryHog ([string]$AppName,[int]$MemoryLimit) {
|
Function Stop-MemoryHog ([string]$AppName,[int]$MemoryLimit) {
|
||||||
$MemoryUsed = (Get-MemoryUsage -AppName $AppName)
|
$MemoryUsed = (Get-MemoryUsage -AppName $AppName)
|
||||||
If ( $MemoryUsed -gt $MemoryLimit ) {
|
If ( $MemoryUsed -gt $MemoryLimit ) {
|
||||||
$MemoryDifference = $MemoryUsed - $MemoryLimit
|
$MemoryDifference = $MemoryUsed - $MemoryLimit
|
||||||
@@ -673,7 +673,7 @@ function Stop-MemoryHog ([string]$AppName,[int]$MemoryLimit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Returns a formatted list of the largest or smallest files in a directory
|
# Returns a formatted list of the largest or smallest files in a directory
|
||||||
function Get-FileSizes {
|
Function Get-FileSizes {
|
||||||
param(
|
param(
|
||||||
[Parameter(ValueFromPipeline=$true)][string]$Path,
|
[Parameter(ValueFromPipeline=$true)][string]$Path,
|
||||||
[switch]$Recurse,
|
[switch]$Recurse,
|
||||||
@@ -724,7 +724,7 @@ function Get-FileSizes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to write text to a file in UTF8 encoding without BOM
|
# Function to write text to a file in UTF8 encoding without BOM
|
||||||
function WriteToFile_UTF8NoBOM {
|
Function WriteToFile_UTF8NoBOM {
|
||||||
param(
|
param(
|
||||||
[Parameter(ValueFromPipeline=$false)][string]$FilePath,
|
[Parameter(ValueFromPipeline=$false)][string]$FilePath,
|
||||||
[Parameter(ValueFromPipeline=$true)][string]$Value
|
[Parameter(ValueFromPipeline=$true)][string]$Value
|
||||||
@@ -735,7 +735,7 @@ function WriteToFile_UTF8NoBOM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to enumerate all user profile folders
|
# Function to enumerate all user profile folders
|
||||||
function EnumUserProfiles {
|
Function EnumUserProfiles {
|
||||||
$ProfilePath = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -Name ProfilesDirectory)
|
$ProfilePath = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -Name ProfilesDirectory)
|
||||||
$UserProfilePaths = @()
|
$UserProfilePaths = @()
|
||||||
ForEach ( $userProfile in (Get-ChildItem -Path $ProfilePath | Where-Object { $_.PSIsContainer }) ) {
|
ForEach ( $userProfile in (Get-ChildItem -Path $ProfilePath | Where-Object { $_.PSIsContainer }) ) {
|
||||||
@@ -745,7 +745,7 @@ function EnumUserProfiles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to test for the presense of a Registry property
|
# Function to test for the presense of a Registry property
|
||||||
function Test-RegistryProperty {
|
Function Test-RegistryProperty {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)][string]$Path,
|
[Parameter(Mandatory=$true)][string]$Path,
|
||||||
[Parameter(Mandatory=$true)][string]$Name
|
[Parameter(Mandatory=$true)][string]$Name
|
||||||
@@ -757,5 +757,37 @@ function Test-RegistryProperty {
|
|||||||
Catch { Return $false }
|
Catch { Return $false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to format a quantity of bytes into a denomination
|
||||||
|
Function Beautify-Bytes {
|
||||||
|
param(
|
||||||
|
[int64]$Amount,
|
||||||
|
[int]$Precision=2,
|
||||||
|
[string]$Units,
|
||||||
|
[switch]$WithUnitLabel
|
||||||
|
)
|
||||||
|
Switch ( $Units.ToUpper() ) {
|
||||||
|
"KB" { $UnitLabel = "KB" ; $Divisor = 1KB }
|
||||||
|
"MB" { $UnitLabel = "MB" ; $Divisor = 1MB }
|
||||||
|
"GB" { $UnitLabel = "GB" ; $Divisor = 1GB }
|
||||||
|
"TB" { $UnitLabel = "TB" ; $Divisor = 1TB }
|
||||||
|
default { $UnitLabel = "bytes" ; $Divisor = 1 }
|
||||||
|
}
|
||||||
|
Switch ( $WithUnitLabel ) {
|
||||||
|
$true { Return (ZeroPad-Decimal -Amount $([Math]::Round($Amount / $Divisor,$Precision)) -NeededDecimalPlaces $Precision) + "${UnitLabel}" }
|
||||||
|
$false { Return (ZeroPad-Decimal -Amount $([Math]::Round($Amount / $Divisor,$Precision)) -NeededDecimalPlaces $Precision) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to pad zeros onto the end of a decimal number
|
||||||
|
Function ZeroPad-Decimal {
|
||||||
|
param(
|
||||||
|
$Amount,
|
||||||
|
$NeededDecimalPlaces
|
||||||
|
)
|
||||||
|
$splitNumbers = $Amount.ToString().Split('.')
|
||||||
|
$paddedDecimal = $splitNumbers[1].PadRight($NeededDecimalPlaces, '0')
|
||||||
|
Return $splitNumbers[0] + '.' + $paddedDecimal
|
||||||
|
}
|
||||||
|
|
||||||
Setup-MSPDirectories
|
Setup-MSPDirectories
|
||||||
Setup-LogFile
|
Setup-LogFile
|
||||||
Reference in New Issue
Block a user