<# 1. Gather list of computers from an OU in AD 2. Gather list of computers from a group in AD, this is the exclude list 3. Omit all computers from list 1 that are in list 2. 3b. Maybe we can output this to a log, or test to see what ones are live when running. 4. foreach computer in list 3 - Restart-Computer #> $smtp = 'smtp1.email.us' $from = "reboot@email.com" $subject = "Reboot Log" $computers = Get-ADComputer -filter * -SearchBase "OU=YOURINFO,OU=YOURINFO,OU=YOURINFO,DC=YOURINFO,DC=YOURINFO,DC=YOURINFO" -Properties MemberOf | Where-Object { $_.memberof -notcontains "CN=OmitFromWeeklyReboot,OU=Groups,OU=YOURINFO,OU=YOURINFO,DC=YOURINFO,DC=YOURINFO,DC=YOURINFO" } | Select-Object -ExpandProperty DNSHostName | sort-object #This will process each computer in list 3 foreach($computer in $computers) { restart-computer -ComputerName $computer -Force if($? -eq $true) { $body += "$computer Rebooted Successfully</b>" } else { $body += "$computer Did Not Reboot</b>" } } Send-MailMessage -SmtpServer $smtp -To email@whatever.com -From $from -Subject $subject -Body $body -BodyAsHtml
Brain fart, not the task manager LOL, but the Task Scheduler.
EDIT: Bad Syntax thanks /u/yeah_i_got_skills
submitted by /u/DeathBoT
[link] [comments]
The post My take on a weekly reboot script. Its run via the task Manager. I saw someone post about it, mine is very simple. Crits welcomed appeared first on How to Code .NET.