src/windows/public/generic.ps1
# _________________________________________ # | | # # | generic.ps1 | # # |_________________________________________| # # ========================= # # GENERIC # # # DESCRIPTION : everything generic for all APPs. # Set-Terminate(). # DESCRIPTION : end program. # RETURN : break. function Launch-Terminate([int]$CODE) { Break; } # Test-Root(). # DESCRIPTION : check if you are root / local administrator. # RETURN : int code. function Test-Root() { [Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains 'S-1-5-32-544'; } # Get-Hostname(). # DESCRIPTION : get hostname device. # RETURN : string. function Get-Hostname() { return $env:COMPUTERNAME; } # Get-UserCurrent(). # Get-UserLogged(). # DESCRIPTION : get hostname device. # RETURN : string. function Get-UserLogged([string]$COMPUTER) { $SESSION = quser /server:$COMPUTER; If ($SESSION) { [string]$RESULT = ((($SESSION) -Split '\n' | Select-Object -Skip 1 ) -Replace '\s+', ';' -Split ';')[1]; } Else { [bool]$RESULT = $False; } return $RESULT; } # Test-UserLogged(). # Get-OSName(). # Get-OSVersion(). # Get-OSMode(). # Get-OSInterface(). # DESCRIPTION : get interface device. # RETURN : string. function Get-OSInterface() { # test : server OR desktop. If ((Get-CimInstance Win32_OperatingSystem).ProductType -gt 1) { return "server"; } Else { return "desktop"; } } # Get-OSLanguage(). # DESCRIPTION : get current language. # RETURN : string. function Get-OSLanguage() { return $(Get-WinSystemLocale).Name; } # Test-ServiceRunning(). # Test-Dir(). # DESCRIPTION : check directory. # RETURN : string. function Test-Dir([string]$PATH,[string]$NAME,[bool]$CREATE) { If (!$($NAME)) { If (Test-Path -Path "$PATH") { return $True; } Else { If ($CREATE -eq $True) { New-Item -ItemType "directory" -Path "$PATH" } return $False; } } Else { If (Test-Path -Path "$NAME") { return $True; } Else { If ($CREATE -eq $True) { New-Item -ItemType "directory" -Path "$PATH" } return $False; } } } # Test-File(). # DESCRIPTION : check file. # RETURN : string. function Test-File([string]$PATH,[bool]$CREATE,[string]$CONTENT,[bool]$OVERWRITE,[bool]$QUIET) { If (Test-Path -Path "$PATH") { [bool]$RESULT = $True; } Else { If ($CREATE -eq $True) { New-Item -ItemType "file" -Path "$PATH" -Force | Out-Null; } [bool]$RESULT = $False; } If ((-not([string]::IsNullOrWhiteSpace($CONTENT))) -And ($OVERWRITE -eq $True)) { Set-Content -Path "$PATH" -Value "$CONTENT" | Out-Null; } If ($QUIET -ne $True) { return $RESULT; } } # Set-Digit(). # DESCRIPTION : display a number with a specific digit. # RETURN : string. function Set-Digit([int]$NUMBER,[int]$DIGIT) { $RESULT = "{0:d$DIGIT}" -f [int]$NUMBER; return $RESULT; } |