Alright, it’s time I started blogging about PowerShell. In fact it’s so long overdue that I really don’t know were to get started. There are so many great resources and blogs available now that most people who are motivated to use PowerShell have already gotten off the starting block.
I suppose the best way to get started with PowerShell is to just open the console and start using the DOS or UNIX commands that you may already be used to.
Right, open the PowerShell console and start typing these familiar commands: DIR, CD and MD.
As you can see, they all still work. As do CLS, MKDIR, COPY etc. That’s because they are in fact PowerShell Alias’s. This means that they’re just PowerShell commands with familiar names. Here’s a few common ones.
|MKDIR, MD||New-Item –ItemType Directory|
PowerShell commands also have the ability to be run in a script with the .ps1 extension but running scripts are disabled by default for security purposes. Firstly, you will need to set the Execution Policy. The cmdlet Get-ExecutionPolicy will show you that the initial policy is set to ‘Restricted’. This will prevent scripts from running. You can change it with the Set-ExecutionPolicy cmdlet. There are four options Restricted, Remote-signed, Signed and Unrestricted. I recommend Remote-Signed as it will allow you to run the scripts that you have created locally and still keep your machine secure. So, just type
Now you can use notepad to create your first script. In Notepad type:
Write-Host "Hello World"
This will need to be saved in a file called something like MyScript.ps1.
Then from a PowerShell console type
The reason you need the .\ is because a PowerShell security feature ensures that you are targeting a specific script in a specific location,. And that’s all there is to it.
Congratulations, you’re now a PowerShell scripter! Now, all you need to do is build up your vocabulary.