Running PowerShell Scripts
With security first on everyone's minds these days it is not too surprising that PowerShell is fairly locked down by default. The file extension you should use for PowerShell scripts is PS1. Most of the examples you will see are of single commands you may run in PowerShell to return desired details about your system, however you can create scripts just as you do with VBscript. If you have a script file you wish to run, there are a couple of security enhancements that make this a slight challenge until you know what is going on...
If you don’t have PowerShell yet, you can get it here:
http://www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx
If you need a sample script to run, past the following into notepad and save it as BIOSinfo.txt
$wmiColl = Get-WmiObject Win32_BIOS *foreach-Object{
Write-Output ("Manufacturer: " + $wmiColl.Manufacturer)
Write-Output ("SerialNumber: " + $wmiColl.SerialNumber)
Write-Output ("Version: " + $wmiColl.Version)
}
If you save your script to a folder named C:\Scripts, and then go there in a command prompt you might expect the following command to work:
powershell BIOSinfo.ps1
However, PowerShell takes this to mean that you are trying to run some command called “BIOSinfo.ps1” and returns the following error:
The term BIOSinfo.ps1' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
To distinguish commands from script files, yo must specify a path to the script file. But we are already in the right directory! To specify current directory use a period and a forward slash like so:
powershell ./BIOSinfo.ps1
Another regular road-block to those staring at PowerShell for the first time is that by default you may not run unsigned script files. To run this script without first having it signed it by a trusted source, you will need to change the default restrictions for running script files. By default, you will see the following error when trying to run this script:
File C:\temp\BIOSinfo.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
Take the advice and use the command offered to learn more! To see how your system is currently set run “get-executionpolicy”. The default is “Restricted”. The following are valid settings you may set using Set-ExecutionPolicy:
Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned – Only scripts signed by a trusted publisher can be run.
RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted – No restrictions; all Windows PowerShell scripts can be run.
To relax security enough to run unsigned scripts, run the following:
Set-ExecutionPolicy RemoteSigned
Note that it is best to stay secure and sign your scripts; I’ll be covering more on PowerShell in upcoming articles so come back soon!

Email This!
Digg it!
Del.icio.us
Reddit!
Newsvine