PowerShell is a command-line tool for the Windows operating system. Compared to the well-known graphical user interface, PowerShell offers more powerful capabilities. This article introduces 10 common PowerShell commands for managing Windows cloud servers, making it easier to administer Windows systems.
1. Viewing Processes
Get-Process
Get-Process <进程名>
Get-Process allows you to view all processes, similar to Task Manager, and also view specific processes by name. For example, to view a process named 'QQ':
PS C:\Users\zhaomu> Get-Process QQ
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
1353 431 149580 122660 584.36 18168 10 QQ
1388 438 155184 136044 631.73 26900 10 QQ
1368 445 152992 154404 629.13 30140 10 QQ
2. Terminating a Process
Stop-Process -id <Process ID>
After obtaining the ID of a process through Get-Process, you can terminate that process using the above command.
3. Viewing File Content
Get-Content <File Name>
PowerShell also makes it easy to view the contents of a file.
4. Viewing File Properties
$(Get-Item <File Name>).LastAccessTime
You can use the Get-Item command to view the properties of a file. The example above is for checking the last access time of a file.
For more ways to use this command, please refer to:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-item
5. Adding a User
New-ADUser -SamAccountName "william" -GivenName "William" -Surname "Edwards" -DisplayName "William David Edwards"
With the above command, we added a user named William, specifying the user's first and last name, as well as their display name.
6. Deleting a User
Remove-ADUser william
Just as users can be added, they can also be deleted.
7. Disabling a User
Disable-ADAccount william
It's also possible to prevent a user from logging in.
8. Adding a User Group
New-ADGroup -name "staff" -groupscope Global
Added a user group named 'staff' and specified that the group's scope is Global.
9. Deleting a User Group
Remove-ADGroup staff
Deleted the user group named 'staff'.
10. Viewing Members of a User Group
Get-ADGroupMember -identity <User Group Name>
This command allows you to view the members of a specific user group.
These are 10 commonly used PowerShell commands. In some cases, using PowerShell commands is more efficient and faster than using a graphical interface.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58