User Tools

Site Tools


microsoft:powershell_script_scheduler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
microsoft:powershell_script_scheduler [2019/02/26 14:35]
admin
microsoft:powershell_script_scheduler [2019/02/26 14:43] (current)
admin
Line 38: Line 38:
 First you need to set the ExecutionPolicy. You have two options here, you can set the ExecutionPolicy on the machine or you can do it on a per-script basis. Read the PowerShell ExecutionPolicy link below as it talks about or you can issue the command: First you need to set the ExecutionPolicy. You have two options here, you can set the ExecutionPolicy on the machine or you can do it on a per-script basis. Read the PowerShell ExecutionPolicy link below as it talks about or you can issue the command:
  
 +<code winbatch>​
 Get-Help About_execution_policies Get-Help About_execution_policies
 +</​code>​
  
 To set the execution policy globally, you can issue this command from within PowerShell: To set the execution policy globally, you can issue this command from within PowerShell:
  
 +<code winbatch>​
 Set-ExecutionPolicy Unrestricted Set-ExecutionPolicy Unrestricted
 +</​code>​
 Or use one of the other settings available depending on your environment. In the context of this how-to, however, we want to set the execution policy on a per script basis and open up security for us to run the script. This security policy will only be in effect for the script we are running and not compromise security otherwise. Or use one of the other settings available depending on your environment. In the context of this how-to, however, we want to set the execution policy on a per script basis and open up security for us to run the script. This security policy will only be in effect for the script we are running and not compromise security otherwise.
  
 That means we use the following Argument: That means we use the following Argument:
  
 +<code winbatch>​
 -ExecutionPolicy Bypass -ExecutionPolicy Bypass
 +</​code>​
 +
 +===== Set the next argument =====
  
-Step 5: Set the next argument 
-Expand 
 Next comes the path and name of your script. This can be either a drive letter path, or a full UNC. I've run into problems using the -FILE parameter so I don't use it. Next comes the path and name of your script. This can be either a drive letter path, or a full UNC. I've run into problems using the -FILE parameter so I don't use it.
  
 +<code winbatch>​
 c:​\scripts\myscript.ps1 c:​\scripts\myscript.ps1
 +</​code>​
 +
 +{{ :​microsoft:​powershell_script_scheduler_04.jpg?​direct&​800 |}}
 +
 +===== Add parameters =====
 +
 +{{ :​microsoft:​powershell_script_scheduler_05.jpg?​direct&​800 |}}
  
-Step 6: Add parameters 
 If your script has any parameters, you want to add them now: If your script has any parameters, you want to add them now:
  
 +<code winbatch>​
 -RunType $true -Path c:​\mydatafiles -RunType $true -Path c:​\mydatafiles
 +</​code>​
  
 Please keep in mind these arguments/​parameters are purely as an example, many scripts won't have any arguments at all. Please keep in mind these arguments/​parameters are purely as an example, many scripts won't have any arguments at all.
  
-Step 7: Full Argument+===== Full Argument ​===== 
 That makes your full argument line look like so: That makes your full argument line look like so:
  
 +<code winbatch>​
 -ExecutionPolicy Bypass c:​\scripts\myscript.ps1 -RunType $true -Path c:​\mydatafiles -ExecutionPolicy Bypass c:​\scripts\myscript.ps1 -RunType $true -Path c:​\mydatafiles
 +</​code>​
 +
 +===== Save the scheduled task =====
 +
 +{{ :​microsoft:​powershell_script_scheduler_06.jpg?​direct&​800 |}}
  
-Step 8: Save the scheduled task 
-Expand 
 Save your scheduled task and run it. Save your scheduled task and run it.
  
microsoft/powershell_script_scheduler.1551188122.txt.gz · Last modified: 2019/02/26 14:35 by admin