Skip to content

PowerShell Scripts

In short, PowerShell is a powerful scripting language launched by Microsoft, much more powerful than CMD commands, and capable of performing complex functions. With today's powerful AI, you can quickly generate the script code you need.

Whatever function you need the script to perform, just ask AI to generate the corresponding PowerShell script code. The example code below was also generated by AI, and requires PixStart version 2.0.4.

1. Open the Downloads folder and select the most recently created file

$folder = "C:\Users\Gao\Downloads"

$latestFile = Get-ChildItem -Path $folder -File |
    Sort-Object CreationTime -Descending |
    Select-Object -First 1

explorer "/select,`"$($latestFile.FullName)`""

2. Visit an IP website, get my IP, and copy it to the clipboard

$url = "https://2026.ip138.com/"

Write-Host "`n[1] 正在访问网页..."
$response = Invoke-WebRequest -Uri $url -UseBasicParsing

$html = $response.Content

Write-Host "`n[2] 网页长度:$($html.Length)"
Write-Host "`n[3] 网页前 500 字符:"
Write-Host ($html.Substring(0, [Math]::Min(500, $html.Length)))

Write-Host "`n[4] 尝试匹配 IP..."

if ($html -match '(\d+\.\d+\.\d+\.\d+)') {
    $ip = $matches[1]
    Set-Clipboard $ip
    Write-Host "[SUCCESS] 提取到 IP:$ip" -ForegroundColor Green
    Write-Host "[OK] 已复制到剪贴板"
} else {
    Write-Host "[FAIL] 未找到 IP"
}