Thursday, April 26, 2012

Scripting Games 2012 Advanced Event 3

Advanced Event 3:

<#
.DESCRIPTION
    This script create log information that updates information about OS,User ...
.LINK
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/04/2012-scripting-games-advanced-event-3-create-a-log-that-updates.aspx  
#>
$os= Get-WmiObject Win32_OperatingSystem
$comp = Get-WmiObject win32_ComputerSystem
$net = Get-WmiObject Win32_NetworkLoginProfile | sort -descending LastLogon | select * -first 1
$prn = Get-WmiObject win32_printer -Filter "Default=True"
$mappeddrives=Get-WmiObject win32_logicaldisk -filter "DriveType=4" | `
              Select-Object @{Name="Drive Letter";Expression={$_.DeviceID}}, `
                            @{Name="Resource Path";Expression= {$_.ProviderName}}
$output = New-Object PSObject
$output | Add-Member noteproperty LastReboot ($os.ConvertToDateTime($os.LastBootUpTime))
$output | Add-Member noteproperty ComputerName (($comp.DNSHostname) + "." + ($comp.Domain))
$output | Add-Member noteproperty Username ($comp.Username)
$output | Add-Member noteproperty OperatingSystemVersion ($os.Version)
$output | Add-Member noteproperty CurrentLog ($os.ConvertToDateTime($net.LastLogon))
$output | Add-Member noteproperty OperatingSystemServicePack ([string]($os.ServicePackMajorVersion) + "." + `
                                                              [string]($os.ServicePackMinorVersion))
$output | Add-Member noteproperty DefaultPrinter ($prn.Name)
$output | Add-Member noteproperty Drive $mappeddrives
$output | Add-Member noteproperty TypeofBoot ($comp.bootupstate)

$output| Out-File -append ($os.Systemdrive + "\logonlog\logonstatus.txt")

No comments:

Post a Comment