Advertisement
Guest User

Xmltask

a guest
Apr 25th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Run PowerShell with administrator permissions.
  2. If(!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
  3. {
  4.     Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
  5. }
  6. Else
  7. {
  8.  
  9.     <############################################## Import Scheduled Task ##############################################
  10.     $STS = New-Object -ComObject("Schedule.Service")
  11.     $STS.connect("localhost")
  12.     $rootFolder = $STS.GetFolder("\")
  13.  
  14.     $ImportPath = "C:\Scripts\*.xml" # Set import path, you need to have access to it.
  15.     $tUser      = ""                # Set username
  16.     $tPassword  = "                       # Set password
  17.     $NameFolder = ""                    # Set folder name
  18.  
  19.     # If folder does not exist, create it
  20.     $rootFolder.CreateFolder("$NameFolder") | Out-Null
  21.  
  22.     # Set folder
  23.     $Folder = $STS.GetFolder("\$($NameFolder)")
  24.  
  25.     # Import task
  26.     Get-Item $ImportPath | %{$tName = $_.Name.Replace('.xml', '')
  27.                             [String]$tXml = Get-Content $_.FullName
  28.                             $Task = $STS.NewTask($null)
  29.                             $Task.XmlText = $tXml
  30.                             $Folder.RegisterTaskDefinition($tName, $Task, 6, $tUser, $tPassword, 1, $null)}
  31.     #>
  32.  
  33.  
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement