Jump to content
RESET Forums (homeservershow.com)

PowerShell for the WHS? (from show 69)


Recommended Posts

  • 7 months later...

I've blogged about installing PowerShell version 2 onto WHS here http://richhewlett.com/2010/07/06/installing-powershell-on-windows-home-server/


I'm surprised that this forum post didn't get more interest. PowerShell is an awesome tool to manage Windows Servers including WHS. I'm converting all my batch scripts over to PowerShell as it provides more flexibility and power. It's worth checking out if you do any sort of automation on your server.

Link to comment
Share on other sites

A quick look at your blog looks like PowerShell is probably geared towards someone with a programming background and not the average hobbyist.


However, I think many of us would be interested in learning how you have used it to create your automation and what you are using it to accomplish.

Link to comment
Share on other sites

It's fair to say that I have taken to Powershell easily becuase I am a software developer, but PowerShell is geared towards the IT Professional as opposed to developers. Which is interesting as developers don't often see the benefits either. The majority of literature on PowerShell is aimed at IT System Administrators and those with some experience writing scripts to automate tasks on Windows. If you use batch scripts to do scheduled tasks then that experience wil prove useful as PowerShell supports normal command line actions. If you open up PowerShell (its included in Windows 7) and type "dir" or "cls" etc then they will perfrom the same actions as if you did them from the normal Windows comamand prompt. It basically provides a shell environment for Windows that can be scripted it allows you to automate tasks through scripting.


If you're not the sort of guy who's comfortable in at the commandline then it can be a little duanting at first but once you grasp the basic concepts its easy to increase your skill level bit by bit. You can start with some simple actions and then over time the flexibility is there for you to move to more advanced actions, or just make use the the huge free scripts on the web that others have already written.


It's installed by default with Windows 7 so you can see it in Start>All Programs>Accessories>Windows PowerShell>Windows PowerShell. It is an optional Windows Update on WHS. So what useful things can you do with PowerShell that a WHS power user might like? Well the vague answer is most actions that you do to your PC or Server in the OS manually can be automated. Some more specific examples are noted below:


Backup Scripts: Previously I wrote simple batch files that use RoboCopy to copy data from my server shares to a backup location. For example a batch script for copying data to an external USB Drive only if its turned on and then automatically disconnect if after the copy. These were standard batch scripts that I automated through Task Scheduler. I'm now migrating these over to PowerShell for a few reasons. PowerShell provides an error handling framework so I can react to errors in the copy process so success or failure of the process results in a message to my Twitter Account and an event logged in the Server's EventLog. I can still make use of the excellent RoboCopy tool though to do the file copying. PowerShell makes it easier to perform simple tasks such as formatting a date for the log file etc.


There are numerous resources available around automating Virtual Machines which is useful if you have a lot of VMs.


For those of you that re-install Windows a lot (maybe building test WHS servers from the 90 day trial installs) you'll probably find that you perform regular activities each time. Perhaps you set up the same shares, create the same users & groups, change the machine's workgroup etc...all these could be put into a PowerShell script that you run after each build.


It's not just for scripting as it gives great realtime information to you on hopw your machine is running etc. All the information that is availabe through WMI (Windows Managment Information) is available in PowerShell. I can open up PowerShell and see all the processes running on the local (or a remote machine): In the PowerShell console just type: Get-Process


Same goes for Services that are running (just type Get-Service). Sure I can get this from Task Manager, but with PowerShell I

can query the results to show all processes begining with the letter "W" for example:

In the PowerShell console just type: Get-Service W*


I can stop/start/resume services, kill processes, and dump out results to file. This line below gets all services and outputs Status,Name and DisplayName properties for them to a HTML page in one line:

Get-Service | Select-Object Status, Name, DisplayName | ConvertTo-HTML | Out-File C:\Scripts\Test.htm


As with Services & Processes I can also query users, groups, files/folders, shares and the Eventlog. To view all errors in the System Eventlog I can just run this line:

Get-Eventlog -logname System -entrytype "Error"


Other examples where it might prove useful are: file copy/delete/merge, rename computer, list Windows Updates, disable hardware, list software installed on PC, download PodCasts, close all running applications, changing system settings, list all files changed since a given time, monitor free space on drives, delete files older than X days, interact with MS Office or email, read system info like number of RAM slots etc, resolve IP address, shut down Windows...etc.


Not only are these tasks useful to do locally but all this can be done remotely too as PowerShell provides the abiulity to run these commands on a remote machine (such as our server).


So I hope thats a taister on the subject. There is a learning curve involved with it as with anything powerful but it is easy to get started and like a lot of tools its only when you know how to use the tool that you find invaluable uses for it.


For more information check out


Wikipedia summary

Great blog and bags of examples

Microsoft Guide

More script examples from Microsoft Technet

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...