OK, I am back. I have 4 scripts at this point in my toolbelt that does certain things each of them work. These are all account previsioning and maintenance scripts. (Thank you everyone for your insight in getting them working properly), now I am taking my next step by turning them to functions and pulling them all together into an advance function.
Basically I will have a csv file with user account information and a computer for the new employee and create using accounts with certain attributes added to the new AD user accounts and computer objects. At this point when I try to run my Advance function I am getting an error on a line but I am not able to figure out what the error is trying to tell me to be able to fix it.
Below is the script that calls the script with the advance functions and provides the location and name of the input csv file with user info.
C:\Powershell\AdAccountManagementAutomator.ps1
$Employees = Import-Csv -Path C:\Powershell\NewUsersInput.csv
foreach ($Employee in $Employees) {
try {
Create the AD user accounts
$NewUserParams = @{
‘FirstName’ = $Employee.FirstName
‘MiddleInitial’ = $Employee.MiddleInitial
‘LastName’ = $Employee.LastName
‘Title’ = $Employee.Title
}
if ($Employee.Location) {
$NewUserParams.Location = $Employee.Location
}
Grab the username created to use for Set-MyAdUser
$Username = New-EmployeeOnboardUser @NewUserParams
Create the employee’s AD computer account
New-EmployeeOnboardComputer -Computername $Employee.Computername
Set the description for the employee’s computer account
Set-MyAdComputer -Computername $Employee.Computername -Attributes @{‘Description’ = “$($Employee.FirstName) $($Employee.LastName)'s computer” }
Set the dept the employee is in
Set-MyAdUser -Username $Username -Attributes @{‘Department’ = $Employee.Department}
} catch {
Write-Error “$($.Excetion.Message) = Line Number: $($.InvocationInfo.ScriptLineNumber)”
}
}
Below is the error I get when I run this script.
PS C:\powershell> C:\Powershell\CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
C:\Powershell\CsvImportExample.ps1 : = Line Number: 17
- CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,CsvImportExample.ps1
Any Ideas on what might be causing these errors? I can tell you also that the csv file has 8 users to be created in it (which looks like the same amount of errors being thrown).