zororec
30-11-2015, 07:57
Доброе утро!
Уважаемы Администраторы и Знатоки PowerShell помогите пожалуйста исправить код.
Хочу чтобы вместе с информацией о печати также выводилось ФИО, департамент и подразделение.
$a3 = Measure-Command -Expression {
$StartTime = "01/10/2015 06:00:01 PM"
$EndTime = "31/10/2015 23:59:01 PM"
$Events=Get-WinEvent -ComputerName SRVPRINT -FilterHashTable @{LogName="Microsoft-Windows-PrintService/Operational";id=307; StartTime=$StartTime; EndTime=$EndTime}
$Events1=$Events |
% { [xml]$_ } |
% {
$User = Get-ADUser $_.Event.UserData.DocumentPrinted.Param3 -Properties DisplayName,Company,Department -ErrorAction SilentlyContinue;
if ($_.Event.UserData.DocumentPrinted.Param7 -is [array] ) {
New-Object PSObject -Property @{
time = $_.Event.System.TimeCreated.SystemTime;
docName = $_.Event.UserData.DocumentPrinted.Param2;
Username = $_.Event.UserData.DocumentPrinted.Param3;
DisplayName = $User.DisplayName;
Company = $User.Company;
Department = $User.Department;
Computer = $_.Event.UserData.DocumentPrinted.Param4;
PrinterName = $_.Event.UserData.DocumentPrinted.Param5;
PrinterPort = $_.Event.UserData.DocumentPrinted.Param6;
PrintSize = [int]$_.Event.UserData.DocumentPrinted.Param7[0];
PrintPages = [int]$_.Event.UserData.DocumentPrinted.Param7[1];
FileDate = $filedate;
}
} else {
New-Object PSObject -Property @{
time = $_.Event.System.TimeCreated.SystemTime;
docName = $_.Event.UserData.DocumentPrinted.Param2;
Username = $_.Event.UserData.DocumentPrinted.Param3;
DisplayName = $User.DisplayName;
Company = $User.Company;
Department = $User.Department;
Computer = $_.Event.UserData.DocumentPrinted.Param4;
PrinterName = $_.Event.UserData.DocumentPrinted.Param5;
PrinterPort = $_.Event.UserData.DocumentPrinted.Param6;
PrintSize = [int]$_.Event.UserData.DocumentPrinted.Param7;
PrintPages = [int]$_.Event.UserData.DocumentPrinted.Param8;
FileDate = $filedate;
}
}
}
$Events1 | export-csv -Path "C:\10010.2015.csv" -NoTypeInformation
}
$a3
Уважаемы Администраторы и Знатоки PowerShell помогите пожалуйста исправить код.
Хочу чтобы вместе с информацией о печати также выводилось ФИО, департамент и подразделение.
$a3 = Measure-Command -Expression {
$StartTime = "01/10/2015 06:00:01 PM"
$EndTime = "31/10/2015 23:59:01 PM"
$Events=Get-WinEvent -ComputerName SRVPRINT -FilterHashTable @{LogName="Microsoft-Windows-PrintService/Operational";id=307; StartTime=$StartTime; EndTime=$EndTime}
$Events1=$Events |
% { [xml]$_ } |
% {
$User = Get-ADUser $_.Event.UserData.DocumentPrinted.Param3 -Properties DisplayName,Company,Department -ErrorAction SilentlyContinue;
if ($_.Event.UserData.DocumentPrinted.Param7 -is [array] ) {
New-Object PSObject -Property @{
time = $_.Event.System.TimeCreated.SystemTime;
docName = $_.Event.UserData.DocumentPrinted.Param2;
Username = $_.Event.UserData.DocumentPrinted.Param3;
DisplayName = $User.DisplayName;
Company = $User.Company;
Department = $User.Department;
Computer = $_.Event.UserData.DocumentPrinted.Param4;
PrinterName = $_.Event.UserData.DocumentPrinted.Param5;
PrinterPort = $_.Event.UserData.DocumentPrinted.Param6;
PrintSize = [int]$_.Event.UserData.DocumentPrinted.Param7[0];
PrintPages = [int]$_.Event.UserData.DocumentPrinted.Param7[1];
FileDate = $filedate;
}
} else {
New-Object PSObject -Property @{
time = $_.Event.System.TimeCreated.SystemTime;
docName = $_.Event.UserData.DocumentPrinted.Param2;
Username = $_.Event.UserData.DocumentPrinted.Param3;
DisplayName = $User.DisplayName;
Company = $User.Company;
Department = $User.Department;
Computer = $_.Event.UserData.DocumentPrinted.Param4;
PrinterName = $_.Event.UserData.DocumentPrinted.Param5;
PrinterPort = $_.Event.UserData.DocumentPrinted.Param6;
PrintSize = [int]$_.Event.UserData.DocumentPrinted.Param7;
PrintPages = [int]$_.Event.UserData.DocumentPrinted.Param8;
FileDate = $filedate;
}
}
}
$Events1 | export-csv -Path "C:\10010.2015.csv" -NoTypeInformation
}
$a3