Index of every page on this site: llms.txt
All skills
jyasuu avatar

/powershell

@d3e2684
Run it yourself

Cheat sheet for PowerShell commands and scripts.

  • 1 file
  • 3.8 KB
  • Updated 10 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/jyasuu/cheat-sheet/powershell

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈15 tokens for metadata: the name and description. ≈961 when used: this file.

How this Skill uses context

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈61 characters, or 0.8%.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Get-ChildItem Env:
$env:Path = "C:\Users\leo.yen\.local\bin;$env:Path"
(Get-PSReadlineOption).HistorySavePath
# https://1fichier.com/?123&af=3957104&token=cHRfalB%2BWVBCD3BzWjhQZ15TQRlwdF1w
# https://1fichier.com/?123

$ErrorActionPreference = "STOP"
# URL of the file you want to download https://1fichier.com/?123
$url = "http://a-33.1fichier.com/456?inline"

$file = "E:\download.zip"
if (!(Test-Path $file)) {
    # 若檔案不存在,用單純 Invoke-WebRequest 或 WebClient.DownloadFile 就好
    # (New-Object System.Net.WebClient).DownloadFile($url, $file)
    Invoke-WebRequest -Uri $url -OutFile $file
}
else {
    # .NET 工作目錄與 PowerShell 可能不用,取得完整路徑供 .NET 使用
    $fileFullPath = (Resolve-Path $file).Path    
    # 若檔案存在,查現有檔案大小,使用 Range Header 續傳
    # 取得現有檔案大小,由後面續傳
    # PowerShell 7 Invoke-WebRequest 直接加 -Resume 即可
    $currLength = (Get-Item $file).Length
    # Invoke-WebRequest -Uri $url -Headers @{"Range"="bytes=$currLength-"} -OutFile "$file.resume"
    # 以上寫法不 Work -> The 'RANGE' header must be modified using the appropriate property or method.
    # 用 HttpWebRequest 實現
    [System.Net.HttpWebRequest] $req = [System.Net.WebRequest]::Create($url)
    $req.Method = "GET"
    $req.AddRange($currLength)
    try {
        $resp = $req.GetResponse()
    }
    catch [System.Net.WebException] {
        # 若檔案先前已下載完成,伺服器會由 Range 已到檔案結尾回傳 HTTP 416,此時不需續傳,直接結束
        if ($_.Exception.Response.StatusCode -eq [System.Net.HttpStatusCode]::RequestedRangeNotSatisfiable) {
            Write-Host "檔案已完成"
            return
        }
        else {
            $_.Exception
        }
    }
    Write-Host "從 $currLength 開始續傳"
    $respStream = $resp.GetResponseStream()
    $contRange = $resp.Headers['Content-Range'] # ex: Content-Range: bytes 0-50/1270
    if (!$contRange) { throw "無法續傳" }
    $totalLen = $contRange.Split('/')[1]
    $fileStream = New-Object System.IO.FileStream($fileFullPath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read)
    try {
        $fileStream.Seek($currLength, [System.IO.SeekOrigin]::Begin) | Out-Null
        # 以 8K 為單位從 Response Stream 讀取 byte[] 寫入 FileStream
        [byte[]]$buff = [byte[]]::CreateInstance([byte], 8192)
        do {
            $bytesRead = $respStream.Read($buff, 0, $buff.Length)
            $fileStream.Write($buff, 0, $bytesRead)
            Write-Progress -Activity "續傳下載中" -Status "$($fileStream.Position)/$totalLen" -PercentComplete ($fileStream.Position * 100 / $totalLen)
        } while ($bytesRead -gt 0)
        $fileStream.Close()
    }
    finally {
        $fileStream.Dispose()
    }
    $respStream.Close()
}
Get-Process | Where-Object {$_.ProcessName -like "*python*"}

Get-CimInstance Win32_Process |
    Where-Object { $_.Name -like "python*" } |
    Select-Object ProcessId, Name, CommandLine
function Get-ParentChain {
    param(
        [int]$ProcessId
    )

    $proc = Get-CimInstance Win32_Process -Filter "ProcessId = $ProcessId"

    if (-not $proc) {
        return @()
    }

    if ($proc.ParentProcessId -eq 0) {
        return @($proc)
    }

    return @($proc) + (Get-ParentChain -ProcessId $proc.ParentProcessId)
}


Get-CimInstance Win32_Process |
    Where-Object { $_.Name -like "python*" } |
    ForEach-Object {
        $chain = Get-ParentChain -ProcessId $_.ProcessId

        [PSCustomObject]@{
            PID          = $_.ProcessId
            Name         = $_.Name
            ParentChain  = ($chain | Select-Object -ExpandProperty Name) -join " -> "
        }
    }

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at d3e2684. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 10 months ago

README badge

README badge for jyasuu/cheat-sheet/powershell