请为此提出前进的方向,同样我必须为 enddate、用户名等示例:
$StartDate, $String = "", ""
$StartDate = Read-Host -Prompt 'Enter the start date of the logs, Ex: 17/07/2017 09:00:00 '
if ($StartDate -and ( $StartDate -ne " ") -and ($StartDate -ne "")) {
$StartDate = $StartDate -replace "`t|`n|`r", ""
$String += " -After '$StartDate'"
} else {
'You did not enter a valid Start date!'
}
echo "Get-EventLog -LogName Application $String"
Get-EventLog -LogName Application $String
输出:
Get-EventLog -LogName 应用程序-在 '19/07/2017' 之后 Get-EventLog:无法绑定参数“InstanceId”。无法转换价值 “-After '19/07/2017'”输入“System.Int64”。错误:“输入字符串不是 以正确的格式。” 在 C:\Users\kumars2\Downloads\Santosh\Powershell 脚本\Enhancements\查看日志示例\small_test.ps1:17 char:13 + 获取事件日志 <<<< -LogName 应用程序 $String + CategoryInfo : InvalidArgument: (:) [Get-EventLog], ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetEventLogCommand