Answer the question
In order to leave comments, you need to log in
How to make PowerShell script work in WinSrv 2008?
Good day friends! There is a task to carry out audit of an input/exit of users on the server. After searching the open spaces, I realized that it is better to implement this with a Powershell script. There is an "almost" finished script:
param ($key1,$val1,$val2,$val3,$val4,$val5,$val6)
if ($val1 -eq $null) {$val1=0};
$mydate = Get-date -hour 0 -minute 0 -second 0;
if ($key1 -eq "year") { $mydate = (Get-date -hour 0 -minute 0 -second 0 -day 1 -month 1); $mydate = $mydate.addyears(-$val1); };
if ($key1 -eq "month") { $mydate = (Get-date -hour 0 -minute 0 -second 0 -day 1); $mydate = $mydate.addmonths(-$val1); };
if ($key1 -eq "day") { $mydate = $mydate.adddays(-$val1) };
if ($key1 -eq "date") { $mydate = (Get-date -hour 0 -minute 0 -second 0 -day $val1 -month $val2 -year $val3); }; # здесь реализуем возможность задания интервала
if ($val4 -eq $null) {$Events = Get-EventLog security -message "*Тип входа:?10*" -after ($mydate) | ?{$_.eventid -eq 4624 }}
if ($val4 -ne $null) {$Events = Get-EventLog security -message "*Тип входа:?10*" -after ($mydate) -before (get-date -hour 0 -minute 0 -second 0 -day $val4 -month $val5 -year $val6) | ?{$_.eventid -eq 528 }}
$Data = New-Object System.Management.Automation.PSObject
$Data | Add-Member NoteProperty Time ($null)
$Data | Add-Member NoteProperty UserName ($null)
$Data | Add-Member NoteProperty Address ($null)
$Events | %{
$Data.time = $_.TimeGenerated
$message = $_.message.split("`n") | %{$_.trimstart()} | %{$_.trimend()}
$Data.UserName = ($message | ?{$_ -like "Пользователь:*"} | %{$_ -replace "^.+:."} )
$Data.Address = ($message | ?{$_ -like "Адрес сети источника:*"} | %{$_ -replace "^.+:."})
$textcolor = $host.ui.rawui.foregroundcolor
$host.ui.rawui.foregroundcolor = "red"
if ($data.address -like "192.168.222*") {$host.ui.rawui.foregroundcolor = "DarkGreen"}
$data
$host.ui.rawui.foregroundcolor = $textcolor
}
Answer the question
In order to leave comments, you need to log in
At the moment, I have fixed errors in starting the script, but now it does not work correctly, displays the time but does not display two more data fields :
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question