Like many administrators, I have numerous scripts written as .BAT batch files that could use an update. Now that Windows Server 2008 R2 has PowerShell 2 installed by default, it is time.
Let's take a few of the staples that we have put in .BAT files, and I'll give you the PowerShell equivalent.
Reboot a remote computer
To perform a 10-second delay on a remote server (Server1), the following is entered in a batch file:
shutdown /r /m \\SERVER1 /f /t 10In a PowerShell file, the equivalent is:
Start-Sleep 10 Restart-Computer -Force -ComputerName SERVER1Restart a service
To restart the DNS cache service on a Windows Server, the following would have been entered in a batch file:
sc stop dnscache sc start dnscacheWithin PowerShell, the equivalent is:
Restart-Service dnscacheMap a drive
In a DOS window or a batch file, the following command would be used to map a drive to a network computer:
Net use L: \\server1\c$With a PowerShell prompt, the equivalent is:
New-PSDrive -name L -psprovider FileSystem -root \\server1\c$Note: A PSDrive is not the same as other drives; this file system space is contained to PowerShell.
While these are the simplest commands, if you replace your day-to-day scripts with PowerShell, you will be equipped with better scripts. These scripts can include richer automation options, yet still be launched interactively in PowerShell.
For additional resources, check out the PowerGUI community, the Windows PowerShell homepage, and these TechRepublic blogs: