この関数は、リモートPC上にインストールされているソフトウェアのリストを取得します。この関数の特殊な特長は、日付をyyyyMMdd
からMM/dd/yyyy
に変換することです。この関数が機能している間に、InstallDate
のオブジェクトを削除しています。私はこのエラーを取得する:パイプラインでのエラー処理
Exception calling "ParseExact" with "3" argument(s).
function Get-Software {
param ([string[]]$ComputerName)
[scriptblock]$code = {
$keys = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ItemProperty -Path $keys |
Where-Object { $_.DisplayName -ne $null } |
Where-Object { $_.DisplayName -notlike '*update*' } |
sort DisplayName |
ForEach-Object {
[PSCustomObject]@{
Display = $_.DisplayName;
Installed = Get-Date ([DateTime]::ParseExact($_.InstallDate, 'yyyyMMdd', $null)) -format d
}
}
}
Invoke-Command -ScriptBlock $code -ComputerName $ComputerName -ArgumentList * |
ft Display, Installed -AutoSize |
Out-File "$Env:USERPROFILE\Desktop\SWinv.txt"
}
Get-Software RemotePC
私はすべてのオブジェクトを返すために何ができますか?
正確にはどのような '$ _。インスタllDate'はいつもあなたのインストール日はありませんか?_空/ヌルですか? 0? – gravity