none
Bulk import MDT computers into MDT database RRS feed

  • Question

  • Hi Everyone!

    I found this really nifty tool online that helped me import all my computers into my MDT database.  Unfortunately, it didn't bring in a bunch of other info that I was hoping it would "auto-detect" as part of the naming scheme.  I am going back and trying to fix this and have already blown up the origional DB and replaced it with a new one, but when I try to add the new parameters (OSDComputerName, DomainAdmin, JoinDomain, etc), it kicks back an error that I don't understand and haven't been able to find a good answer for online.  Here is the code I want to use:

    $computers=import-csv C:\Users\user\Desktop\MDTDB\MdtSqlUpload.csv
    
    import-module C:\Users\user\Desktop\MDTDB\MDTDB.psm1
    Connect-MDTDatabase –sqlServer sqlserver –database mssql
    
    For ($i=1; $i -le $computers.count; $i++)
    
    {
    New-MDTComputer -macAddress $computers[$i-1].mac -uuid $computers[$i-1].UUID -description $computers[$i-1].name -settings @{OSInstall='YES'; OSDComputerName=$computers[$i-1].name; DomainAdmin='administrator'; DomainAdminDomain='domain.local'; DomainAdminPassword='iR1337Haxx0rz!'; JoinDomain='domain.local';;
     }
    }

    and I get the error of "Missing expression after '&' in pipeline element" which makes NO sense to me as there are no pipes in use!!  So, I ask for your help in figuring out why this is happening and how do I get past it.  I have checked out the ps1 file you are supposed to import, and it says nothing about the OSInstall option and what the settings would be.

    If you have a link to that, I may be able to make some progress, but until then, I'm stuck.  Any and all answers are appreciated.


    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Thursday, January 17, 2019 8:23 PM

Answers

  • Your code has many syntax and coding errors.  This will move you in abetter direction:

    import-module C:\Users\user\Desktop\MDTDB\MDTDB.psm1
    Connect-MDTDatabase –sqlServer sqlserver –database mssql
    
    $settings = @{
        OSInstall       = 'YES'
        OSDComputerName = $null
        DomainAdmin     = 'administrator'
        DomainAdminDomain = 'domain.local'
        DomainAdminPassword = 'iR1337Haxx0rz!'
        JoinDomain      = 'domain.local'
    }
    import-csv C:\Users\user\Desktop\MDTDB\MdtSqlUpload.csv |
        ForEach-Object{
    $settings.OSDComputerName = $_.Name New-MDTComputer -macAddress $_.mac -uuid $_.UUID -description $_.name -settings $settings }


    \_(ツ)_/


    • Edited by jrv Thursday, January 17, 2019 9:08 PM
    • Marked as answer by Obujuwami Wednesday, January 23, 2019 6:02 PM
    Thursday, January 17, 2019 9:07 PM

All replies

  • Your code has many syntax and coding errors.  This will move you in abetter direction:

    import-module C:\Users\user\Desktop\MDTDB\MDTDB.psm1
    Connect-MDTDatabase –sqlServer sqlserver –database mssql
    
    $settings = @{
        OSInstall       = 'YES'
        OSDComputerName = $null
        DomainAdmin     = 'administrator'
        DomainAdminDomain = 'domain.local'
        DomainAdminPassword = 'iR1337Haxx0rz!'
        JoinDomain      = 'domain.local'
    }
    import-csv C:\Users\user\Desktop\MDTDB\MdtSqlUpload.csv |
        ForEach-Object{
    $settings.OSDComputerName = $_.Name New-MDTComputer -macAddress $_.mac -uuid $_.UUID -description $_.name -settings $settings }


    \_(ツ)_/


    • Edited by jrv Thursday, January 17, 2019 9:08 PM
    • Marked as answer by Obujuwami Wednesday, January 23, 2019 6:02 PM
    Thursday, January 17, 2019 9:07 PM
  • Thanks for the help jrv!  I understand why this works way better than the other way, but I am confused on if the OSDComputerName will be pulled from the CSV file.  In the CSV file, I have AssetTag labeled as the computer name, and when I look at the modules code, it does reach out and grab that info, but I don't see where the OSDComputerName would be getting it's info from.  There is no "$_.Name", but would it work to change that to "$_.AssetTag"?

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Tuesday, January 22, 2019 10:38 PM
  • We have no idea what you put in your CSV file.  I just fixed what you posted.


    \_(ツ)_/

    Tuesday, January 22, 2019 11:02 PM
  • Yeah, didn't think about that...but my question still stands.  Would replacing $_.name with $_.AssetTag do the same thing?

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Only you know what is in your CSV file.

    \_(ツ)_/

    Wednesday, January 23, 2019 5:30 PM
  • I tried it with the swap, and it looks like it worked just fine.  Thank you very much for you help with this and I will pass on what I learned here to the website where I found the solution.

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, January 23, 2019 6:02 PM