hinemos executes powershell scripts under windows

Purpose:

Execute scripts under windows through hinemos

 

Process:

Create a powershell script

I have never written a script under Windows before. The first time I wrote a powshell script, I struggled for a while.

After reading several articles on the Internet, I found that the command line of powshell and the command line of cmd are quite similar.

for example:

Switch to D drive ⇒ D:

Generate a powershell file and enter the string to the file ⇒'"hello powershell!"'>test.ps1

Execute the powershell file ⇒ .\test.ps1 ⇒ so that hello powershell! will be printed

 

But in general, the first time it will be unsuccessful, I encountered it. Because Powershell generally disables script execution during initialization. Whether the script can be executed or not depends on Powershell's execution policy.

.\test.ps1 When executing the above command, it shows that the script cannot be loaded because script execution is prohibited in this system. See "get-help about_signing" for details.

Location Line: 1 Char: 15
+ .MyScript.ps1 < <<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException

Then you need to change the policy at this time, remember that only administrators have permission to change this policy. Non-administrators will report an error.

Change Policy Steps:

1. View Policy ⇒ Get-ExecutionPolicy

2.Restricted modification policy⇒Set-ExecutionPolicyUnRestricted

Unrestricted: The highest authority, can execute any script without restriction.

After the modification is completed, execute it, there is no problem.

In order to clearly demonstrate the successful execution of a powershell script on windows from Hinemos, decided to write a script about "create file".

The command is as follows:

1. Write the script to create the file into test.ps1, 'New-Item C:\Users\Administrator\test.txt -type file' > test.ps1

2. Through the dir command, it is found that test.ps1 is indeed generated in the C:\Users\Administrator\ directory,

3. Execute the script ./test.ps1, and indeed the test.txt file is also generated under C:\Users\Administrator\

4. Delete the test.txt file rm test.txt

 

This successfully created a "create file" powershell file, and then configured it in hinemos.

 

Configure Hinemos job

How to execute the script through the job function under hinemos. In fact, it is very simple, similar to executing a shell under Linux

Write powershell -Command C:\Users\Administrator\test.ps1 in the startup command under the command tab

 

result

After the job is executed, the status of the job is normal, and then go to the actual Windows machine, under the C:\Users\Administrator\ directory, to generate the test.txt file. Then the job is indeed executed normally.

 
 
 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326457870&siteId=291194637