You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编写PowerShell脚本提取Test注册表项的Version和Server值

Got it, here's a PowerShell script tailored to your needs, plus breakdowns of how each part works so you can tweak it if needed:

# Define the base registry path where your "Test" key lives
$baseRegPath = "HKLM:\Software\Test"

# First, make sure the base path exists to avoid errors
if (-not (Test-Path -Path $baseRegPath)) {
    Write-Error "Oops, the registry path $baseRegPath doesn't exist. Double-check the location!"
    exit 1
}

# Grab all direct subkeys under the "Test" key
$subkeys = Get-ChildItem -Path $baseRegPath

# Loop through each subkey to extract your required values
foreach ($subkey in $subkeys) {
    # Pull the "Version" string value from the current subkey
    $version = Get-ItemProperty -Path $subkey.PSPath -Name "Version" -ErrorAction SilentlyContinue | 
               Select-Object -ExpandProperty Version

    # Build the path to the "Setting" subkey and get the "Server" value
    $settingSubPath = Join-Path -Path $subkey.PSPath -ChildPath "Setting"
    $serverValue = if (Test-Path -Path $settingSubPath) {
        Get-ItemProperty -Path $settingSubPath -Name "Server" -ErrorAction SilentlyContinue | 
        Select-Object -ExpandProperty Server
    } else {
        "Not found"
    }

    # Format and print the result exactly as you requested
    $versionDisplay = $version ?? "Not found"
    $serverDisplay = $serverValue ?? "Not found"
    Write-Host "$($subkey.PSChildName) Version: $versionDisplay Server: $serverDisplay"
}

Quick Notes & Customization Tips

  • Update the Base Path: Change $baseRegPath to match your actual registry location (e.g., HKCU:\Software\Test if it's under the current user's hive instead of the local machine).
  • Handling Missing Values: The script uses -ErrorAction SilentlyContinue and null-coalescing (??) to gracefully handle cases where a subkey lacks the "Version" value, or the "Setting" subkey doesn't exist. It'll just show "Not found" for missing values instead of crashing.
  • Output Options: If you want to save the results to a file instead of just printing to the console, replace Write-Host with Add-Content -Path "C:\your-output-file.txt" to append each line to a text file.

内容的提问来源于stack exchange,提问作者SebastianS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 06:54:42