powershell - Dynamically pass values to get-winevent -
i using below code pass values get-winevent, getting compilation issue, values passed if exist, please suggest
$startdate = read-date "enter start date of logs, ex: 17/07/2017 or 17/07/2017 09:00:00" $enddate = read-date "enter end date of logs, ex: 19/07/2017 or 19/07/2017 10:00:00" $message = read-host $prompt 'message/string search' if ($startdate) { $params['starttime'] = $startdate } if ($enddate) { $params['endtime'] = $enddate } $event_logs_content = get-winevent -filterhashtable {@params}
this option list available log can see asterisk after "-logname", worth filter specific one.
$startdate = read-date "enter start date of logs, ex: 17/07/2017 or 17/07/2017 09:00:00" $enddate = read-date "enter end date of logs, ex: 19/07/2017 or 19/07/2017 10:00:00" $message = read-host $prompt 'message/string search' $startdate=get-date $startdate -format "yyyy-mm-ddthh:mm:ss" $enddate=get-date $enddate -format "yyyy-mm-ddthh:mm:ss" $event_logs_content = get-eventlog -logname * -after $startdate -before $enddate
Comments
Post a Comment