Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

Script Control

published: November 26, 2014 author: Tinu tags: Scripting categories: PowerShell


Script Steuerung

Am Ende des Scriptfiles (der Prozedur) wird die ganze Ablaufsteuerung vorgenommen.

#region script control
if($PSVersionTable.PSVersion.Major -ge 4){
Set-StrictMode -Version latest
if($Error.Count -gt 0){$Error.Clear()}
if($psdebug){
    $ErrorActionPreference = 'Stop'
}
else{
    $ErrorActionPreference = 'SilentlyContinue'
}

"$(Get-Date -DisplayHint DateTime) [INFORMATION] Start $($script:Scriptname), Version $($script:version)" | Out-File -FilePath "$($script:Scriptpath)\$($script:Logfile)" -Append -Encoding default
$script:Scriptreturn += Get-LocalUser -Name Admin
if(!([String]::IsNullOrEmpty($Inputfile)) -and (Test-Path $Inputfile)){
    Get-Content $Inputfile
}
else{
    "$(Get-Date -DisplayHint DateTime) [  WARNING  ] Inputfile '$($Inputfile)' not found" | Out-File -FilePath "$($script:Scriptpath)\$($script:Logfile)" -Append -Encoding default
}
$duration = $([math]::round(((New-TimeSpan $($Global:ScriptStart) $(get-date)).TotalMinutes),2))
"$(Get-Date -DisplayHint DateTime) [INFORMATION] End $($script:Scriptname), Duration $($duration) Minutes, Errorcount $($Error.Count)" | Out-File -FilePath "$($script:Scriptpath)\$($script:Logfile)" -Append -Encoding default
#Calculate the duration of this script
#load the current logfile
Get-Content "$($script:Scriptpath)\$($script:Logfile)" -raw

$script:Scriptreturn
#endregion
}

Ich glaube dieser Code ist selbsterklärend, falls nicht bitte via Kontaktformular melden.


← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →