共用方式為


Useful builds for cmdlet scripting

Many administrators find it laborious to build scripts from scratch, while many can download existing scriptlets and cmdlets in the web and then modify it, there are more DOS commands that are available since NT 4 / Windows 2000. Here are some examples:

Just open start, type Run, and then at the command windows, type the following commands with the /? switch.

  1. How do you encrypt via cmdlets? Use the Cipher.exe command
  2. How do you compress via cmdlets? Use the Compact.exe command
  3. How do you assign NTFS permisison via cmdlets? Use the Cacls.exe (deprecated) or Icacls.exe command
  4. How do you ping with hop count info? Use Pathping.
  5. How do you create user in a non-AD based environment or in legacy environments where DsAdd commands are not available? Use net user. For example: net user kitty Pa$$w0rd /ad = This creates a user named Kitty with a password of Pa$$w0rd
  6. How do you reset password via command? net user kitty * = You will be prompted for entering new password, this is a password reset command
  7. How do you create global group? Use net group, for example: net group "Sales Managers" /ad = This creates a global group Sales Managers in your domain. Note that you can only issue this command on a DC (Domain Controller)
  8. How do you add/nest multiple new users into a group? net group "Sales Managers" user1 user2 user3 user4 /ad (Provided that Sales Managers global group exists, and all user1, user2, user3 and user4 exist)
  9. How do you create a local group? Use net localgroup, for example: net localgroup Reports /ad
  10. How do you add/nest a localgroup into a global group? net group "Sales Manager" Reports /ad (Provided that global group Sales Managers and local group Reports exist)
  11. What is the command to launch the Remote Desktop Connection? Use mstsc.exe
  12. How do you share / unshared a folder? net share
  13. How do you connect to a map drive / create a map drive? net use
  14. How do you create  computer account? net computer
  15. How do you shutdown multiple remote PCs? Shutdown.exe with corresponding switches
  16. How do you access the SAM Lock Tool? Syskey.exe
  17. How do you refresh the computer policy on a legacy Windows OS? Secedit /refreshpolicy machine_policy or on newer OS use Gpupdate /?  or use the GUI in the latest release. See https://support.microsoft.com/kb/227302 (Using SECEDIT to Force a Group Policy Refresh Immediately). More info https://support.microsoft.com/kb/313222
  18. How do you synchronize computer's time including domain controllers? net time
  19. Ho do you write a script to restart a service? Write a batch file (*.bat) which has the following contents net stop ServiceNameA and next line net start ServiceNameA
  20. How do you rename an Active Directory domain name? Rendom, see https://technet.microsoft.com/en-us/library/cc732097(v=WS.10).aspx
  21. How do you rename a computer name in legacy OS? netdom, see https://support.microsoft.com/kb/298593. There are multiple netdom subcommands associated with netdom, see https://technet.microsoft.com/en-us/library/cc772217(v=WS.10) and https://technet.microsoft.com/en-us/library/cc788049(v=WS.10).aspx.
  22. How do you jetpack a DHCP database? Jetpack.exe, see https://social.technet.microsoft.com/wiki/contents/articles/jetpack-exe-on-windows-2008-server.aspx
  23. How do you manage, create and delete partition via cmdlets? diskpart
  24. How do you convert a FAT partition to NTFS? Convert <Volume> /fs: ntfs. This typically happens on earlier Windows Server versions scenarios where after upgrading a Windows Server to a newer version, you would convert its file system from FAT (File allocation table) to NTFS.
  25. You can create a batch file (*.bat) by using the net user command in order to create multiple users with just one click, for example, create a batch file (*.bat) that has the following contents
  • net user Operator1 Pa$$w0rd /ad
  • net user Operator2 Pa$$w0rd /ad
  • net user Operator3 Pa$$w0rd /ad
  • net user Operator4 Pa$$w0rd /ad
  • net user Operator5 Pa$$w0rd /ad

Ken Sim, Technical Evangelist, Microsoft Corporation, MCT

Comments

  • Anonymous
    December 27, 2012
    Thanks of the info. Wish can shared with the powershell scripting as well.