Hi
I am trying to assign more than one role to a computer as it is added to the MDT database. The powershell script I am using is well known and works fine when only one role is in the CSV file. I've listed the script below along with the createmachines.csv. My aim is to create a new machine in the database and assign it more than one Role dependant on the entry/entries against it in the csv file. To prove it can be done, there are two lines in the script which I have used. Where I have defined the roles inside the script, they are applied correctly to the computer. Where I try reading the roles from the csv file, I cannot get it to work properly.
I have tried changing the Roles inside the csv file to various formats, for example,
@('Role1,Role2,Role3')
@('Role1','Role2','Role3')
I have tried other formats, but none of the formats I have tried has succeeded in populating the database correctly.
Can anyone shed some light on this problem for me?
Many thanks in advance.
Mike
[createmachines.csv]
name,mac,Role
test1,00:00:00:00:00:01,Role1,Role2,Role3
test2,00:00:00:00:00:02,Role1,Role2,Role3
[CreateMachinesInDatabase.ps1]
Import-Module –name D:\Scripts\MDTDB.psm1 -Force
Connect-MDTDatabase –sqlServer SQLSERVER –instance sqlexpress –database MDT
$machines = Import-Csv D:\Scripts\createmachines.csv
For ($i=1; $i -le $machines.count; $i++)
{
New-MDTComputer -description $machines[$i-1].name -macAddress $machines[$i-1].mac -settings @{
OSInstall='YES';
OSDComputerName=$machines[$i-1].name;
}
# Set the roles in the script works fine
Get-MDTComputer -macAddress $machines[$i-1].mac | Set-MDTComputerRole -roles @('Role 1','Role 2');
#Set the roles reading the csv fails
Get-MDTComputer -macAddress $machines[$i-1].mac | Set-MDTComputerRole -roles $machines[$i-1].Role;
}