0% found this document useful (0 votes)
10 views6 pages

TR EB Ps CMD

Uploaded by

Delfcosta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

TR EB Ps CMD

Uploaded by

Delfcosta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

20 POWERSHELL CMDLETS

YOU CAN USE INSTEAD OF


CMD COMMANDS
By Jesus Vigo

COPYRIGHT ©2018 CBS INTERACTIVE INC. ALL RIGHTS RESERVED.


20 POWERSHELL CMDLETS YOU CAN USE INSTEAD OF CMD COMMANDS

INTRODUCTION
When Microsoft developed PowerShell (PS) in November 2006, the aim was to marry a command-line
based interface and a scripting language to handle task automation and configuration management of native
Microsoft applications. Through the years it has seen upgrades that increase its functionality, with more cmdlets
(PS commands) and more support through importing modules to grant the framework greater flexibility in
managing a variety of services.

As PowerShell’s popularity has increased, its adoption rate has fueled further changes. Arguably the largest and
most recent of these was Microsoft’s decision to make PS open source, porting it to various Linux distributions
and macOS and enabling cross-platform support through one unified shell. What does this mean for
non-PowerShell users? Simply put, PS is poised to not only replace the venerable command line that Windows
admins know—but as organizations grow their user base with Linux and macOS-based devices, admins can
port that knowledge over to managing those devices as well, all from one console or shell.

For those who support Windows-only organizations, Microsoft has made inroads into PS-based management
by ensuring that much of its higher-level software, such as Windows Server, Active Directory, and Exchange,
will be 100% manageable only through PowerShell. Users managing services through the GUI or admin
consoles won’t be able to fully configure every aspect of the application unless they switch to PowerShell.
So here are some commonly used commands you may find are part of your daily admin tasks—and the PS
equivalent—to help you migrate your usage over to PowerShell.

THE CMDLETS
1. Changing directories
CMD: cd
PS: Set-Location “path/to/directory”

2. Listing files in a directory


CMD: dir
PS: Get-ChildItem

3. Renaming files
CMD: rename
PS: Rename-Item “path/to/file.ext” -NewName “newfilename.ext”

2
COPYRIGHT ©2018 CBS INTERACTIVE INC. ALL RIGHTS RESERVED.
20 POWERSHELL CMDLETS YOU CAN USE INSTEAD OF CMD COMMANDS

4. Getting help for a command


CMD: /?
PS: Get-Help “Cmdlet name”

5. Stopping processes
CMD: taskkill
PS: Stop-Process -Name “application.exe”

6. Forcing Group Policy refresh


CMD: gpupdate /force
PS: Invoke-GPUpdate -Computer “Hostname” -Force

7. Shutting down local (or remote) computer(s)


CMD: shutdown –s
PS: Stop-Computer -ComputerName “Hostname1”,”Hostname2”, “localhost”

8. Restarting local (or remote) computer(s)


CMD: shutdown –r
PS: Restart-Computer -ComputerName “Hostname3”, “localhost”

9. Setting variables
CMD: SET variable=”value”
PS: $”variablename” = “value”

10. Joining a computer to a domain


CMD: netdom /domain:domainname /user:username /password:password member hostname /add
PS: Add-Computer -DomainName “Domain” -Credential “Domain\Username” -Restart

3
COPYRIGHT ©2018 CBS INTERACTIVE INC. ALL RIGHTS RESERVED.
20 POWERSHELL CMDLETS YOU CAN USE INSTEAD OF CMD COMMANDS

11. List all commands


CMD: help
PS: Get-Command

12. Clear the screen


CMD: cls
PS: Clear

13. Copy a file (or directory)


CMD: copy “source file/directory” “destination file/directory”
PS: Copy-Item “path/to/file/directory” -Destination “path/to/directory”

14. Delete a file


CMD: del “path/to/file”
PS: Remove-Item “path/to/file”

*Note: PowerShell cmdlet will also delete folders, not just files.

15. Remove a directory


CMD: rmdir “path/to/directory”
PS: Remove-Item path/to/directory”

16. Map network drives


CMD: net use Drive_letter “path/to/shared/folder”
PS: New-PSDrive -Name “Drive_Letter” -PSProvider “FileSystem” -Root “path/to/shared/directory”

17. Get running processes


CMD: tasklist
PS: Get-Process

4
COPYRIGHT ©2018 CBS INTERACTIVE INC. ALL RIGHTS RESERVED.
20 POWERSHELL CMDLETS YOU CAN USE INSTEAD OF CMD COMMANDS

18. Start/stop services


CMD: net start (or stop) “service name”
PS: Start-Service -Name “service name”

*Note: In PS, using “Stop-Service” will stop the desired service.

19. Get (or Set) ACLs for file/folder permissions


CMD: cacls “file or folder name” or cacls /E /P user:perm
PS: Get-ACL “path/to/file/directory” or Set-ACL -Path “path/to/file/directory”

20. Compare two files or directories


CMD: comp “path/to/file1” “path/to/file2”
PS: Compare-Object -ReferenceObject “path/to/file” -DifferenceObject “path/to/file”

STARTING POINT
While this list is in no way exhaustive, it’s a good first step toward treading PowerShell’s relatively deep waters in
a way that allows you to get hands-on experience using it. It also provides a good jumping-off point for those
who want to navigate further into PS and learn more about how its cmdlets can be be used for greater manage-
ability and to automate daily, repetitive tasks.

5
COPYRIGHT ©2018 CBS INTERACTIVE INC. ALL RIGHTS RESERVED.
CREDITS
Global Editor in Chief ABOUT TECHREPUBLIC
Jason Hiner
TechRepublic is a digital publication and online community
Editor in Chief, UK that empowers the people of business and technology. It
Steve Ranger
provides analysis, tips, best practices, and case studies
Managing Editor aimed at helping leaders make better decisions about
Bill Detwiler technology.

Editor, Australia DISCLAIMER


Chris Duckett
The information contained herein has been obtained
Senior Features Editors from sources believed to be reliable. CBS Interactive Inc.
Jody Gilbert
disclaims all warranties as to the accuracy, completeness,
Mary Weilage
or adequacy of such information. CBS Interactive Inc. shall
Senior Editor have no liability for errors, omissions, or inadequacies in
Conner Forrest
the information contained herein or for the interpretations
Senior Writer thereof. The reader assumes sole responsibility for the
Teena Maddox selection of these materials to achieve its intended results.
The opinions expressed herein are subject to change
Chief Reporter
Nick Heath without notice.

Staff Writers
Alison DeNisco Rayome
Macy Bayern
Associate Editor Copyright ©2018 by CBS Interactive Inc. All rights reserved. TechRepublic
and its logo are trademarks of CBS Interactive Inc. ZDNet and its logo are
Melanie Wachsman trademarks of CBS Interactive Inc. All other product names or services
identified throughout this article are trademarks or registered trademarks of
Multimedia Producer their respective companies.
Derek Poore

Cover image: iStock/gorodenkoff

You might also like