Guest User

Untitled

a guest
Sep 11th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Import-Module ActiveDirectory
  2. $VerbosePreference = "continue"
  3. $list = (Get-ADComputer -LDAPFilter "(&(objectcategory=computer)(OperatingSystem=*server*))").Name
  4. $logfilepath = "$homeDesktopTasksLog.txt"
  5. $ErrorActionPreference = "SilentlyContinue"
  6.  
  7. invoke-command -ComputerName $list -ScriptBlock { $sched = New-Object -Com "Schedule.Service"
  8. $sched.Connect()
  9. $out = @()
  10. $sched.GetFolder("").GetTasks(0) | % {
  11. $xml = [xml]$_.xml
  12. $out += New-Object psobject -Property @{
  13. "Name" = $_.Name
  14. "Status" = switch($_.State) {0 {"Unknown"} 1 {"Disabled"} 2 {"Queued"} 3 {"Ready"} 4 {"Running"}}
  15. "NextRunTime" = $_.NextRunTime
  16. "LastRunTime" = $_.LastRunTime
  17. "Author" = $xml.Task.Principals.Principal.UserId
  18. }
  19. }
  20.  
  21. $out | fl Name,Status,NextRunTime,LastRunTime,Author, } | Out-File $logfilepath
  22.  
  23. $list = "Server1"
  24.  
  25. $list | ForEach-Object {
  26. Invoke-Command -ComputerName $_ -ScriptBlock { ... }
  27. }
  28.  
  29. $list | ForEach-Object {
  30. Write-Verbose $_ -Verbose
  31. Invoke-Command -ComputerName $_ -ScriptBlock { ... }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment