Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module ActiveDirectory
- $VerbosePreference = "continue"
- $list = (Get-ADComputer -LDAPFilter "(&(objectcategory=computer)(OperatingSystem=*server*))").Name
- $logfilepath = "$homeDesktopTasksLog.txt"
- $ErrorActionPreference = "SilentlyContinue"
- invoke-command -ComputerName $list -ScriptBlock { $sched = New-Object -Com "Schedule.Service"
- $sched.Connect()
- $out = @()
- $sched.GetFolder("").GetTasks(0) | % {
- $xml = [xml]$_.xml
- $out += New-Object psobject -Property @{
- "Name" = $_.Name
- "Status" = switch($_.State) {0 {"Unknown"} 1 {"Disabled"} 2 {"Queued"} 3 {"Ready"} 4 {"Running"}}
- "NextRunTime" = $_.NextRunTime
- "LastRunTime" = $_.LastRunTime
- "Author" = $xml.Task.Principals.Principal.UserId
- }
- }
- $out | fl Name,Status,NextRunTime,LastRunTime,Author, } | Out-File $logfilepath
- $list = "Server1"
- $list | ForEach-Object {
- Invoke-Command -ComputerName $_ -ScriptBlock { ... }
- }
- $list | ForEach-Object {
- Write-Verbose $_ -Verbose
- Invoke-Command -ComputerName $_ -ScriptBlock { ... }
- }
Advertisement
Add Comment
Please, Sign In to add comment