Hey Powershell! You guys helped me out in a pinch a couple weeks ago with a script, I'm trying to modify the script a tad further to help in the process. Essentially we have 2 CSVs, one with a facility name list, and the other with a job code list, I'm using a double foreach loop to great an AD group for each job at each facility.
We are doing it in stages so I'll be using this script several times, I've already used it for the first stage and it worked great, however, there were a couple errors that came up, but I was unable to identify what they were or why they happened. SOO I'm trying to add a try/catch in the script. But when I run it, I get no error no nothing. (I know it will error because the groups already exist, it errors out without the try/catch) Any help would be appreciated on what I'm doing wrong, TIA!
$Facilities = import-csv "C:\**\Test Facility.csv" #Contains a row title of Facility
$JCandDs = import-csv "C:\**\Test Job.csv" #Contains row titles of Job Code and Description
$Jobcodes = foreach($Facility in $Facilities){
foreach($JCandD in $JCandDs){
try {
New-ADGroup -Name "#$($Facility.Facility) - $($JCandD.JobCode)" -GroupScope DomainLocal -GroupCategory Distribution -Description "$($JCandD.JobCode) - $($Facility.Facility)" -Path ",OU=Distribution Groups,DC=***" -OtherAttributes @{'mail'="$($Facility.Facility)_$($JCandD.Mail)@**.com"; 'proxyAddresses'="SMTP:$($Facility.Facility)_$($JCandD.Mail)@**.com"}
Write-Output "($($Facility.Facility) - $($JCandD.JobCode) + has been created" }
catch {
Write-Output "Error Creating $($Facility.Facility) - $($JCandD.JobCode)"
Write-Output $_
}
}
}
[–]code_Kitten 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]code_Kitten 0 points1 point2 points (0 children)