How to Create and Run a PowerShell Script

As you automate your Windows operating system with PowerShell 2, it helps to know how to create scripts that you may be able to loop and use more than once. The steps to create a script follow:



  1. Create the script in a plain text editor such as Notepad and save with a .PS1 file extension (for example, myscript.ps1).



  2. Run the script by entering the full path to the script (c:\scripts\myscript.ps1), or if it’s in the current directory, prefix it with a period followed by a backslash (.\myscript.ps1).



  3. If the path to the script contains a space, enclose the full path in quotation marks and prefix the entire thing with an ampersand (for example: &"C:\my scripts\myscript.ps1").




Unless you’re running a signed script, make sure you to set the correct execution policy using Set-ExecutionPolicy. To allow local scripts to run unsigned, run:


Set-ExecutionPolicy RemoteSigned



dummies

Source:http://www.dummies.com/how-to/content/how-to-create-and-run-a-powershell-script.navId-397925.html

No comments:

Post a Comment