0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分のmemo

Posted at

Windowsのサービス、hotfix、アプリ一覧を各csvで出力する

# 実行ポリシーの変更
Set-ExecutionPolicy Bypass -Scope Process -Force

# サービス一覧を取得
$triggers = Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Services" |
    Where-Object { $_.GetSubkeyNames().Contains("TriggerInfo") } |
    ForEach-Object { $_.Name.Split("\")[-1] }

$startMode = @{ Manual = "手動"; Disabled = "無効"; Auto = "自動"; Unknown = "不明" }
$startOption = @{ 01 = " (トリガー開始)"; 10 = " (遅延開始)"; 11 = " (遅延開始、トリガー開始)" }

$serviceData = Get-CimInstance -ClassName Win32_Service | Select-Object @(
    @{ n = "表示名";              e = { $_.DisplayName } }
    @{ n = "サービス名";          e = { $_.Name } }
    @{ n = "スタートアップの種類"; e = { $startMode[$_.StartMode] + $startOption[10 * ($_.StartMode -eq "Auto" -and $_.DelayedAutoStart) + $triggers.Contains($_.Name)] } }
    @{ n = "状態";                e = { if($_.State -eq "Running") { "実行" } else { "-" } } }
)

# 取得したサービス一覧をcsvに出力
$serviceData | select 表示名,状態,スタートアップの種類 | sort -Property 表示名 | Export-Csv $PSScriptRoot\services.csv -Encoding Default

# 取得したHotFix一覧をcsvに出力
Get-HotFix | select HotFixID,InstalledOn | sort -Property HotFixID | Export-Csv $PSScriptRoot\hotfix.csv -Encoding Default

# インストールされたアプリケーション一覧をcsvに出力
$base = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$wow64 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$path = @(("HKLM:" + $base), ("HKCU:" + $base))
if(Test-Path $wow64){
    $path += $wow64
}

$programs = @()

Get-ChildItem -Path $path | 
    ForEach-Object {
        $properties = Get-ItemProperty -Path $_.PsPath
        if ($properties.systemcomponent -ne 1 -and $properties.parentkeyname -eq $null -and $properties.DisplayName -ne $null) {
            $programs += [PSCustomObject]@{
                DisplayName = $properties.DisplayName
                Publisher = $properties.Publisher
                DisplayVersion = $properties.DisplayVersion
            }
        }
    }

$sortPG = $programs | Sort-Object DisplayName

# CSVファイルのパスを指定
$csvPath = "application.csv"

# CSVファイルのヘッダーを作成
$sortPG | Export-Csv -Path $csvPath -NoTypeInformation
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?