0

selectPowerShell でステートメントのプロパティを保存する方法を見つけようとしていますが、うまくいきません。ステートメント全体をリテラルにして、変数が開かれるまでレビューされないようにする方法が見つかりませんでした。

これが機能するものです:

$wsus.GetSummariesPercomputerTarget($CurrentMonthUpdateScope, $ComputerScope) |
    Select-Object @{L="WSUSServer";E={$Server}},
        @{L="FromDate";E={$($CurrentMonthUpdateScope.FromCreationDate).ToString("MM/dd/yyyy")}},
        @{L="ToDate";E={$($CurrentMonthUpdateScope.ToCreationDate).ToString("MM/dd/yyyy")}},
        @{L='Computer';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetID)).FullDomainName}},
        DownloadedCount,
        NotInstalledCount,
        InstalledPendingRebootCount,
        FailedCount,
        Installedcount |
    Sort-Object -Property "Computer"

Select-Objectそして、同じプロパティを異なるスコープで複数回使用できるように、前述のプロパティ (ステートメントの直後から最後のパイプの直前まで) を変数に配置しようとしています。

私はこれを試しました:

$Properties = '@{L="WSUSServer";E={$Server}},
@{L="FromDate";E={$($CurrentMonthUpdateScope.FromCreationDate).ToString("MM/dd/yyyy")}},
@{L="ToDate";E={$($CurrentMonthUpdateScope.ToCreationDate).ToString("MM/dd/yyyy")}},
@{L="Computer";E={($wsus.GetComputerTarget([guid]$_.ComputerTargetID)).FullDomainName}},
DownloadedCount,
NotInstalledCount,
InstalledPendingRebootCount,
FailedCount,
Installedcount'

$wsus.GetSummariesPercomputerTarget($CurrentMonthUpdateScope, $ComputerScope) |
    Select-Object $Properties |
    Sort-Object -Property "Computer"

これを実行してもデータが得られず、PowerShell が混乱していると思います。

これは同じ応答を返します:

$Properties = "@{L=`"WSUSServer`";E={$Server}},
@{L=`"FromDate`";E={$($CurrentMonthUpdateScope.FromCreationDate).ToString(`"MM/dd/yyyy`")}},
@{L=`"ToDate`";E={$($CurrentMonthUpdateScope.ToCreationDate).ToString(`"MM/dd/yyyy`")}},
@{L=`"Computer`";E={($wsus.GetComputerTarget([guid]$_.ComputerTargetID)).FullDomainName}},
DownloadedCount,
NotInstalledCount,
InstalledPendingRebootCount,
FailedCount,
Installedcount"

オプション、考えなどはありますか?

4

1 に答える 1

2

-Property引数にSelect-Objectは、文字列ではなく配列が必要です。だから、このようなもの:

$Properties = @(@{L="WSUSServer";E={$Server}},
                @{L="FromDate";E={$($CurrentMonthUpdateScope.FromCreationDate).ToString("MM/dd/yyyy")}},
                @{L="ToDate";E={$($CurrentMonthUpdateScope.ToCreationDate).ToString("MM/dd/yyyy")}},
                @{L="Computer";E={($wsus.GetComputerTarget([guid]$_.ComputerTargetID)).FullDomainName}},
                "DownloadedCount",
                "NotInstalledCount",
                "InstalledPendingRebootCount",
                "FailedCount",
                "Installedcount")

単純なプロパティ名を配列内の文字列に変換する必要があることに注意してください。

于 2016-12-15T19:30:11.390 に答える