Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Run PowerShell with administrator permissions.
- If(!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
- {
- Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
- }
- Else
- {
- <############################################## Import Scheduled Task ##############################################
- $STS = New-Object -ComObject("Schedule.Service")
- $STS.connect("localhost")
- $rootFolder = $STS.GetFolder("\")
- $ImportPath = "C:\Scripts\*.xml" # Set import path, you need to have access to it.
- $tUser = "" # Set username
- $tPassword = " # Set password
- $NameFolder = "" # Set folder name
- # If folder does not exist, create it
- $rootFolder.CreateFolder("$NameFolder") | Out-Null
- # Set folder
- $Folder = $STS.GetFolder("\$($NameFolder)")
- # Import task
- Get-Item $ImportPath | %{$tName = $_.Name.Replace('.xml', '')
- [String]$tXml = Get-Content $_.FullName
- $Task = $STS.NewTask($null)
- $Task.XmlText = $tXml
- $Folder.RegisterTaskDefinition($tName, $Task, 6, $tUser, $tPassword, 1, $null)}
- #>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement