Skip to content

PowerShell脚本

长话短说,PowerShell是微软推出的强大的脚本语言,比CMD命令强大的多,可以执行一些复杂功能,借助如今强大的AI,您可以快速生成您需要的脚本代码

需要脚本执行啥功能,可以询问AI生成PowerShell的相关脚本代码就行了,以下示例代码也是AI生成的, 需要使用PixStart 2.0.4版本

1. 打开下载文件夹,并且选中最新创建的一个文件

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

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

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

2. 访问IP网站,获取我的IP并且复制到剪辑版

$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"
}