Linux运维一分钟了解PowerShell

2024-08-27, 杭州

学OffSec课程不可不品的就是对PowerShell的运用,简单记录一下。

系统信息

Get-ComputerInfo
Get-Process
Get-Service
Get-EventLog -LogName Application | Select-Object -First 10

服务管理

Get-Service -Name Tailscale | Format-List
Start-Service -Name Tailscale
Stop-Service -Name Tailscale
Restart-Service -Name Tailscale

网络管理

Get-NetAdapter | Format-List
Get-NetTcpConnection

字符串操作

Select-String -Path hosts -Pattern ''
Get-ComputerInfo | Select-String "OS Name"

用户管理

Get-LocalUser
Get-LocalGroup
Get-LocalGroupMember -Group Administrators

命令行操作

Get-Command ls
Get-Alias
Get-Help Get-Command
Get-Process | ForEach-Object { $_.Name }

实用工具

Get-FileHash -Algorithm SHA256 download.zip
Invoke-RestMethod -Uri https://example.com/api -Method GET
Invoke-Expression -Command "ls"

进阶用法

反射加载dotnet

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

使用WinRM 5985端口远程连接

Enter-PSSession -ComputerName localhost