I got a little fuzzy case of how much disk all our server event-logs consume. Since the purchaser is still on vacation and couldn’t answer any questions I put together a 0.1 version with the old get-eventlog commandlet, depending on meeting with the purchaser I might replace it with the get-winevent that is a little more powerfull. The text displayed to the user is in Swedish since I´m working against swedes. First the script collects all servers in the active directory. After that I built the function get-logs that first collect all event-logs and then calculates the size of all logs and add the size and servername in an pscustomobject variable, it also adds the servers log size to the global variable $total to get a total size from all servers. I then use the function in an foreach loop with all the collected servers as targets. In the end it send a pop-up window to the user asking if he/she wants to export the result to an CSV-file. If you are interested in what the Swedish sentences means I recommend http://translate.google.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
#Global variables [double]$result="" $computerarray = @() [int]$total = "" #Array of computers $servers1 = Get-ADComputer -Filter * -SearchBase "OU=Servers,DC=your,DC=domain,DC=here" $servers2 = Get-ADComputer -Filter * -SearchBase "OU=Server,OU=Data,DC=your,DC=domain,DC=here" $DCs = Get-ADComputer -Filter * -SearchBase "OU=Domain Controllers,DC=your,DC=domain,DC=here" $computers = $servers1 + $servers2 + $DCs #function to collect all eventlogs and check max size and fill function get-logs { param( $computer = $env:COMPUTERNAME ) $logs = Get-EventLog -ComputerName $computer -LogName * | select * [int]$Mbytes = "" foreach ($log in $logs) {$Mbytes += $log.maximumkilobytes } $global:result = $Mbytes * 1024 /1MB $global:total += $result $script:computerarray += New-Object psobject -Property @{ Datornamn = $computer Loggar_i_MB = $result -as [int] } } # Use function get-logs on all computers in array. foreach ($computer in $computers.name) { Write-Host "kollar $computer" get-logs -computer $computer #$computer.name } # Add total size to result array. $script:computerarray += New-Object psobject -Property @{ Datornamn = "Total" Loggar_i_MB = $total } # Export to CSV $title = "Exportera till CSV" $message = "Vill du exportera reslutatet till en CSV fil(C:\temp\comp.csv)?" $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Ja" $no = New-Object System.Management.Automation.Host.ChoiceDescription "&Nej" $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) $result = $host.ui.PromptForChoice($title, $message, $options, 0) switch ($result) { 0 {$computerarray | select Datornamn, Loggar_i_MB | Export-Csv C:\temp\comp.csv -NoTypeInformation} 1 {"OK, allt är klart"} } |