0
点赞
收藏
分享

微信扫一扫

常用Windows PowerShell命令

以下是一些常用的 PowerShell 命令及其用法,涵盖文件操作、系统管理、网络相关命令等多个方面:

文件操作

命令

说明

示例

Get-ChildItem

列出目录中的文件和子目录

Get-ChildItem -Path C:\

Copy-Item

复制文件或目录

Copy-Item -Path C:\file.txt -Destination D:\

Move-Item

移动或重命名文件或目录

Move-Item -Path C:\file.txt -Destination D:\newfile.txt

Remove-Item

删除文件或目录

Remove-Item -Path C:\file.txt

New-Item

创建新文件或目录

New-Item -Path C:\newfile.txt -ItemType File

系统管理

命令

说明

示例

Get-Process

获取正在运行的进程

Get-Process -Name chrome

Stop-Process

停止进程

Stop-Process -Name notepad

Get-Service

获取系统服务信息

Get-Service -Name "Windows Update"

Start-Service

启动服务

Start-Service -Name "Windows Update"

Stop-Service

停止服务

Stop-Service -Name "Windows Update"

Restart-Computer

重启计算机

Restart-Computer -Force

网络相关命令

命令

说明

示例

Test-Connection

测试网络连接

Test-Connection -ComputerName google.com -Count 4

Get-NetIPConfiguration

获取网络配置信息

Get-NetIPConfiguration

Invoke-WebRequest

发送 HTTP 请求

Invoke-WebRequest -Uri "https://www.example.com"

Resolve-DnsName

解析 DNS 名称

Resolve-DnsName -Name www.example.com

进程管理

命令

说明

示例

Get-Process

获取进程信息

Get-Process -Name "powershell"

Stop-Process

终止进程

Stop-Process -Id 1234

Start-Process

启动进程

Start-Process -FilePath "notepad.exe"

用户管理

命令

说明

示例

Get-LocalUser

获取本地用户账户

Get-LocalUser

New-LocalUser

创建本地用户账户

New-LocalUser -Name "NewUser" -Password (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force)

Remove-LocalUser

删除本地用户账户

Remove-LocalUser -Name "OldUser"

服务管理

命令

说明

示例

Get-Service

获取服务信息

Get-Service -Name "W3SVC"

Start-Service

启动服务

Start-Service -Name "W3SVC"

Stop-Service

停止服务

Stop-Service -Name "W3SVC"

Restart-Service

重启服务

Restart-Service -Name "W3SVC"

注册表操作

命令

说明

示例

Get-ItemProperty

获取注册表项属性

Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"

Set-ItemProperty

设置注册表项属性

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "MyApp" -Value "C:\MyApp\app.exe"

Remove-ItemProperty

删除注册表项属性

Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "MyApp"

包管理

命令

说明

示例

Install-Module

安装 PowerShell 模块

Install-Module -Name "AzureAD"

Update-Module

更新 PowerShell 模块

Update-Module -Name "AzureAD"

Remove-Module

卸载 PowerShell 模块

Remove-Module -Name "AzureAD"

脚本与模块管理

命令

说明

示例

Get-Command

获取命令信息

Get-Command -Name "Get-Process"

Get-Help

获取命令帮助信息

Get-Help -Name "Get-Process"

Import-Module

导入模块

Import-Module -Name "ActiveDirectory"

远程管理

命令

说明

示例

Enter-PSSession

进入远程会话

Enter-PSSession -ComputerName "RemotePC" -Credential (Get-Credential)

Invoke-Command

在远程计算机上执行命令

Invoke-Command -ComputerName "RemotePC" -ScriptBlock { Get-Process }

提示

其实,上面这些命令只是 PowerShell 的冰山一角,根据具体需求,您还可以探索更多高级用法和模块。

举报

相关推荐

Windows 常用CMD命令

0 条评论