$AdnServer = "MyServer"
$Qry = "Select Top 2 Name from NOCTools.dbo.ADComputers Where Left(Name,1) in ('E','A')"
$ServerList = Invoke-Sqlcmd -MaxCharLength 10000000 -ServerInstance $AdnServer -Query $Qry
Invoke-Sqlcmd -MaxCharLength 10000000 -ServerInstance $AdnServer -Query "Truncate Table NOCTools.dbo.RebootReport"
$All = @()
foreach ($computer in $ServerList)
{
Get-WinEvent -ComputerName $computer -FilterHashtable @{logname='System'; id=1074} |
ForEach-Object {
$rv = New-Object PSObject | Select-Object Computer,Date, User, Action, Process, Reason, ReasonCode, Comment
$rv.Date = $_.TimeCreated
$rv.Process = $_.Properties[0].Value
$rv.Computer = $_.Properties[1].Value
$rv.Reason = $_.Properties[2].Value
$rv.ReasonCode = $_.Properties[3].Value
$rv.Action = $_.Properties[4].Value
$rv.Comment = $_.Properties[5].Value
$rv.User = $_.Properties[6].Value
} | Select-Object COmputer,Date, Action, Reason, User |select -first 100 | Format-Table -auto #r
}
$Qry2 = "INSERT INTO NOCTools.dbo.RebootReport(Computer,RebootDate,Uptime,[Action],Reason,ADUser,Process)
VALUES ('$rv.Computer','$rv.Date','',$rv.Comment , $rv.ReasonCode ,$rv.User ,$rv.Process)"
Write-Host @Qry2
Invoke-Sqlcmd -MaxCharLength 10000000 -ServerInstance $AdnServer -Query $Qry2
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE