Tech

Guides
 

Update Windows scripts using these handy PowerShell commands

By Rick Vanover, Special to ZDNet Asia
Tuesday, October 20, 2009 01:03 PM
It may be time to upgrade batch files to PowerShell for automating the role of administering a Windows Server.

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 10

In a PowerShell file, the equivalent is:

Start-Sleep 10
Restart-Computer -Force -ComputerName SERVER1

Restart 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 dnscache

Within PowerShell, the equivalent is:

Restart-Service dnscache

Map 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:

Rick Vanover is a systems administrator in Columbus, Ohio. He has more than 12 years of IT experience, and he focuses on virtualization, Windows-based server administration, and system hardware.



WORTHWHILE?

0

0 votes
Blog

Talkback 0 comments

There are currently no comments for this post.


Guest user

Guest user

Level: 
Joined: —
Already a member? Log in »



 

Loading...

Whitepapers/Case Studies

Downloads

Windows Server News



Tech Jobs Now!

Tags

  1. domain controller
  2. environment
  3. group policy
  4. hardware
  5. infrastructure / architecture management
  6. microsoft server 2003
  7. microsoft windows
  8. microsoft windows active directory
  9. microsoft windows powershell
  10. microsoft windows server
  11. microsoft windows server 2008
  12. network
  13. ohio
  14. rick vanover
  15. server
  16. server platforms
  17. servers
  18. storage
  19. tool
  20. virtualization