powershell PowerShell:脚本模板版本2(带日志记录)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell:脚本模板版本2(带日志记录)相关的知识,希望对你有一定的参考价值。
#requires -version 4
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS Log File
The script log file stored in C:\Windows\Temp\<name>.log
.NOTES
Version: 1.0
Author: <Name>
Creation Date: <Date>
Purpose/Change: Initial script development
.EXAMPLE
<Example explanation goes here>
<Example goes here. Repeat this attribute for more than one example>
#>
#---------------------------------------------------------[Script Parameters]------------------------------------------------------
Param (
#Script parameters go here
)
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
#Set Error Action to Silently Continue
$ErrorActionPreference = 'SilentlyContinue'
#Import Modules & Snap-ins
Import-Module PSLogging
#----------------------------------------------------------[Declarations]----------------------------------------------------------
#Script Version
$sScriptVersion = '1.0'
#Log File Info
$sLogPath = 'C:\Windows\Temp'
$sLogName = '<script_name>.log'
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
#-----------------------------------------------------------[Functions]------------------------------------------------------------
<#
Function <FunctionName> {
Param ()
Begin {
Write-LogInfo -LogPath $sLogFile -Message '<description of what is going on>...'
}
Process {
Try {
<code goes here>
}
Catch {
Write-LogError -LogPath $sLogFile -Message $_.Exception -ExitGracefully
Break
}
}
End {
If ($?) {
Write-LogInfo -LogPath $sLogFile -Message 'Completed Successfully.'
Write-LogInfo -LogPath $sLogFile -Message ' '
}
}
}
#>
#-----------------------------------------------------------[Execution]------------------------------------------------------------
Start-Log -LogPath $sLogPath -LogName $sLogName -ScriptVersion $sScriptVersion
#Script Execution goes here
Stop-Log -LogPath $sLogFile
以上是关于powershell PowerShell:脚本模板版本2(带日志记录)的主要内容,如果未能解决你的问题,请参考以下文章
powershell [PS:脚本模板]只是PowerShell脚本要遵循的模板。 #PowerShell #Template
powershell脚本隐藏退出码
powershell 测量PowerShell命令或PowerShell脚本的速度
PowerShell 添加任务以使用参数运行 PowerShell 脚本
PowerShell命令与脚本(10)——脚本
powershell 远程执行bat脚本,去启动一个应用,如何让应用一直运行,powershell能正常退出?