First commit
This commit is contained in:
commit
cce27559b1
9 changed files with 676 additions and 0 deletions
84
lib/backupscript-global_utils.psm1
Normal file
84
lib/backupscript-global_utils.psm1
Normal file
|
@ -0,0 +1,84 @@
|
|||
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
|
Reference in a new issue