Skip to content

Documentation

Yelodress edited this page Nov 12, 2024 · 5 revisions

UFT-8 conversion

If you're facing an issue with special characters in your custom text, consider converting them to UTF-8:

$yourVarName = [System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::Default.GetBytes("Your text"))

Warning messagebox

You can add a messagebox to warn users from what informations you're going to retrieve. Add this on the top of your script:

Add-Type -AssemblyName PresentationFramework # load the assembly .NET framework (to make the script able to create a message box interface)
$caption = "Title"
$messageBoxText = "Description"
$icon = [System.Windows.MessageBoxImage]::Information
$button = [System.Windows.MessageBoxButton]::OKCancel

$msgbox = [System.Windows.MessageBox]::Show($messageBoxText, $caption, $button, $icon) # Mixing all components

if ($msgbox -eq "OK") {
    # User accepted, coninue
}
else {
    # User declined, canceling the script
    exit
}

Adding a step to the progress-bar

Adding a step:

$stepName = "Your Step"
Show-CustomProgressBar -CurrentStep X -TotalSteps $TotalSteps

(do not forget to replace X by your step number)

Progress-bar settings to modify

Replace every X by your total amount of step

$TotalSteps = X 

function Show-CustomProgressBar {
    param (
        [int]$CurrentStep,
        [int]$TotalSteps
    )
    
    $ProgressWidth = 50 
    $ProgressBar = [string]::Join('', ('o' * [math]::Round(($CurrentStep / $TotalSteps) * $ProgressWidth)))
    
    Write-Host -NoNewline "`r[$ProgressBar] $([math]::Round(($CurrentStep / $TotalSteps) * X))/X $stepName"

    if ($CurrentStep -eq $TotalSteps) {
        Write-Host ""  
    }
}

Searching for a specific user/group

Specific user or group

Add this as a new column in $combinedData:

"Specific user" = if (Get-LocalUser -Name "Your username") {"Yes"} else {"No"}
"Specific group" = if (Get-LocalGroup -Name "Your group name") {"Yes"} else {"No"}

Finding a specific software

Add this as a new column in $combinedData:

"Specific software" = $appsList | Where-Object { $_.DisplayName -like "* Your software name *" } | Select-Object -ExpandProperty DisplayVersion -First 1

Note: You can remove the asterisks if you're sure of your exact app name.