Retrieving Detailed Windows Version Information Remotely Using WinRM

This guide explains how to remotely retrieve detailed version information from Windows servers and clients. We will walk through the steps to securely collect system information leveraging WinRM and PowerShell.

目次

Prerequisites

Server-Side Configuration

  1. Checking and changing the network profile
# ネットワークプロファイルの確認
Get-NetConnectionProfile
# プロファイルを変更(必要に応じて)
Set-NetConnectionProfile
-Name "ネットワーク名"
-NetworkCategory Private
  1. Enabling PowerShell Remoting
# PowerShellリモート処理を有効化
Enable-PSRemoting -Force
  1. Adding remote management users
# ドメインユーザーの場合
Add-LocalGroupMember
-Group
"Remote Management Users"
-Member "DOMAIN\ユーザー名"

# ローカルユーザーの場合
Add-LocalGroupMember
-Group
"Remote Management Users"
-Member "ローカルユーザー名"

Client-Side Configuration

  1. Starting the WinRM service
# WinRMサービスの起動
Start-Service WinRM

# WinRM構成の確認
winrm quickconfig
  1. Configuring Trusted Hosts
# リモートサーバをTrustedHostsに追加
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "サーバのIPアドレス" -Force

Script for Retrieving Detailed Version Information

Run this on the client:

# クレデンシャルの作成
$credential = Get-Credential

# リモートコマンド実行
Invoke-Command -ComputerName "サーバのIPアドレス" -Credential $credential -ScriptBlock {
    # Windowsバージョン情報の取得
    $osInfo = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"

    # インストール済みの更新プログラム情報
    $updateInfo = Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 5

    # 結果をカスタムオブジェクトとして返す
    [PSCustomObject]@{
        # OSバージョン情報
        ProductName = $osInfo.ProductName
        CurrentVersion = $osInfo.CurrentVersion
        ReleaseId = $osInfo.ReleaseId
        CurrentBuild = $osInfo.CurrentBuild
        UBR = $osInfo.UBR

        # 追加のバージョン詳細
        BuildLabEx = $osInfo.BuildLabEx
        InstallationType = $osInfo.InstallationType

        # 最近インストールされた更新プログラム
        RecentUpdates = $updateInfo | ForEach-Object {
            [PSCustomObject]@{
                HotFixID = $_.HotFixID
                Description = $_.Description
                InstalledOn = $_.InstalledOn
            }
        }

        # システム全体の更新状況
        LastInstalledUpdate = (Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn
        TotalInstalledUpdates = (Get-HotFix).Count
    }
}

Details of the Output Information

Main information that can be retrieved:

  • Product Name (ProductName)
  • Current Version (CurrentVersion)
  • Release ID (ReleaseId)
  • Current Build Number (CurrentBuild)
  • UBR (Update Build Revision)
  • BuildLabEx (Extended build information)
  • Installation Type
  • Recently Installed Updates (latest 5)
  • Last Update Date
  • Total Number of Installed Updates

Security and Considerations

  • Follow the principle of least privilege.
  • Use secure authentication methods.
  • Pay attention to network security.
  • Keep the system regularly updated.

Troubleshooting

Common Connection Errors

  1. “FullyQualifiedErrorId : CreateRemoteRunspaceFailed"
    • Cause: The user is not added to the “Remote Management Users" group.
    • Solution: Add the user to the group on the server side.
  2. Connection Errors
    • Check the firewall.
    • Review network settings.
    • Verify the status of the WinRM service.

Conclusion

By using WinRM and PowerShell, you can securely and efficiently collect detailed Windows-based system information remotely. Feel free to customize the script according to your environment.

Note: Please adjust appropriately for your actual environment and pay close attention to security.