我是Powerhell的新手,需要帮助。我的第一个工作脚本是使AD环境中的新用户和被称为用户自动化。Powershell - 组合阵列
CSV转储将从我们的Peoplesoft系统每天完成一次。我使用Import-CSV
并创建3个数组(新的,术语和处理)。
我遇到的麻烦是将3个数组组合在一起,我通过所有用户循环并尝试将其放回到文件中。代码在$New += $Term
行中断。我相信这是由于我的测试文件中每个用户类型(新,术语和处理)只有1条记录(我知道,增加更多用户,不能,这对于任何用户来说都是真实世界的结果特定的日子)。以下是我的示例代码:
#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 2013-02-15 21:57:32
添加了代码和错误声明......我的歉意。 – user2077056 2013-02-15 23:18:03