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")

Comments

Popular posts from this blog

How to convert string to Base64 and vice versa using Powershell

Machine domain group policy failed to apply

Install Windows Server 2012 on HP DL 380 G5