私はpowershellを使い慣れていないので、助けが必要です。私の仕事のための最初のスクリプトは、AD環境で新しいユーザーと呼ばれるユーザーを自動化することです。Powershell - アレイを組み合わせる
CSVダンプはPeoplesoftシステムから毎日1回実行されます。 Import-CSV
を使用して、3つの配列(new、term、およびprocessed)を作成します。
私が抱えている問題は、すべてのユーザーを1回ループして3つのアレイを結合し、ファイルに戻してみることです。コードは$New += $Term
行で改行されます。これは、テストファイルに各ユーザータイプ(新規、期間、処理済み)のレコードが1つしかないことが原因であると私は考えている(私は知っている、より多くのユーザーを追加&hellipすることはできない。特定の日)。以下は私のサンプルコードです:
#Get Credentials from user
$c = Get-Credential
#Get Date for $Term array population
$e = Get-Date -format M/d/yyyy
#Set file location and variable for said file
$File = "c:\users\nmaddux\desktop\adduserstuff\test.csv"
#Import record sets for New and Term users
$New = @()
$Term = @()
$Procd = @()
$New = Import-Csv $File | Where-Object {
$_.TermDate -eq "" -and $_.LastName -ne "" -and $_.Processdate -eq ""
}
$Term = Import-Csv $File | Where-Object {
$_.TermDate -ne "" -and $_.Processdate -eq "" -and $_.TermDate -le $e
}
$Procd = Import-Csv $File | Where-Object { $_.Processdate -ne "" }
#Process both new and term users provided there are records to process for each
If ($New -ne $NULL -and $Term -ne $NULL) {
# Some code to process users
}
$new += $term
$new += $Procd
$new | Export-Csv $file -NoTypeInformation -ErrorAction SilentlyContinue
したがって、結果は部分的にしかエクスポートされません。
エラー - [System.Management.Automation.PSObject]に 'op_Addition'という名前のメソッドが含まれていないため、メソッドの呼び出しに失敗しました。
'$ New + = $ Term'そしてその行はどこですか? – aquinas
コードとエラーステートメントを追加しました...謝罪します。 – user2077056