This repository has been archived on 2024-09-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
powershell_backupscript/lib/backupscript-global_utils.psm1
2021-01-15 12:19:10 +01:00

84 lines
No EOL
1.7 KiB
PowerShell

Write-Output "chargement du module"
function Get-LogTimeStamp {
return (Get-Date).toString("yyyy.MM.dd HH:mm:ss")
}
function ConvertTo-CmdlineOptions {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[object]
$options,
[Parameter(Mandatory=$False)]
[string]
$sep=" "
)
Write-Debug "Call parse_options with $options, separator: `"$sep`""
$opt = ""
if ($options -eq $false) {
return ""
}
$options.Keys | foreach {
if ( -not $($options.item($_)) -eq "" ) {
$opt = -join($opt, " $($_)", $sep, "$($options.item($_))")
}
else {
$opt = -join($opt, " $($_)")
}
}
return $opt
}
function Set-Error {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]
$message
)
if ( $global:logfile ) {
Add-Content $global:logfile -Value "$(Get-LogTimeStamp)`tERROR`t$message"
}
else {
Write-Host -ForegroundColor Red $message
}
}
function Set-Warning {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]
$message
)
if ( $global:logfile ) {
Add-Content $global:logfile -Value "$(Get-LogTimeStamp)`tWARN`t$message"
}
else {
Write-Host -ForegroundColor Yellow $message
}
}
function Set-Message {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]
$message
)
if ( $global:logfile ) {
Add-Content $global:logfile -Value "$(Get-LogTimeStamp)`tINFO`t$message"
}
else {
Write-Host "$message"
}
}
Export-ModuleMember -Function ConvertTo-CmdlineOptions, Set-Message, Set-Warning, Set-Error