これはデータ型変換の問題です。PowerShell出力をハッシュテーブル配列に変換します(データ型変換)
私はSCCMからコンピュータの名前を取得し、それをSCCMレポートに送り込もうとしています。レポートコマンドレットは、変数に "Computer Name"という名前を付ける必要があるハッシュテーブルを受け取ります。値はコンピュータ名です。
ex. $computer = @{"Computer Name" = "MyComp01"}
コマンドレットの出力例(SCCMからコンピュータ名を取得)これは動作します。
$unknownoutputtype = Get-CMDevice -CollectionName "My Collection Computers" | select @{N="Computer Name";E={$_.Name}}
--Output--
Computer Name
-------------
MyComp01
MyComp02
MyComp03
MyComp04
MyComp05
MyComp06
PS> $unknownoutputtype.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
Recievingコマンドレットの例(工程クエリ)これは動作します:
$computer = @{"Computer Name" = "MyComp01"}
invoke-cmreport -ReportPath "Software - Companies and Products/Software registered in Add Remove Programs on a specific computer" -reportparameter $Computer -OutputFormat excel
私は以下の種類として出力する "ゲット・CMDeviceを" 行を必要としています。
PS> $Computer.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
マイ失敗し
PS> Get-CMDevice -CollectionName "My Collection Computers" |select @{N="Computer Name";E={$_.Name}} | Foreach-object {invoke-cmreport -ReportPath "Software - Companies and Products/Software registered in Add Remove Programs on a specific computer" -SiteCode "MySite" -reportparameter $_ -OutputFormat Excel}
エラー出力:
Invoke-CMReport : Cannot bind parameter 'ReportParameter'. Cannot convert value "@{Computer Name=MyComp01}" to type "System.Collections.Hashtable". Error: "Cannot convert the "@{Computer Name=MyComp01}" value of type
"Selected.Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject" to type "System.Collections.Hashtable"."
At line:1 char:280
+ ... s on a specific computer" -SiteCode "{removed}" -reportparameter $_ -Output ...
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-CMReport], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ConfigurationManagement.Cmdlets.Reporting.Commands.InvokeReportCommand
の代わりに選択してみてください: 'foreachのオブジェクト{。。@ {$ _名= $ _名}}' 選択をハッシュではなくオブジェクトを返す – Sigitas