locked
Import computers from csv Powershell RRS feed

  • Question

  • Hi,

    I'm trying to import some computers within sccm via Powershell but get the following error:

    PS STC:\> $Computers = Import-Csv "C:\computers.csv"
    $CollectionName = "STC - W7 - Deploy"
    ForEach ($Workstation in $Computers)
    {
       Import-CMComputerInformation -ComputerName $Workstation.Name -MacAddress $Workstation.Mac -CollectionName $CollectionName
    }

    Import-CMComputerInformation : Cannot validate argument on parameter 'MacAddress'. System.Management.Automation.ValidationMetadataException
    At line:5 char:77
    + ...  -ComputerName $Workstation.Name -MacAddress $Workstation.Mac -Collec ...

    ---

    Csv contains:

    Name,Mac
    Computer1,0C:51:8F:7E:3D:04

    Please advise.
    J.


    Jan Hoedt

    Friday, April 24, 2015 11:36 AM

Answers

All replies

  • Hello,

    Try to enable column headings: Import-CMComputerInformation


    David Gustafsson

    Friday, April 24, 2015 11:54 AM
  • Have a look at the EnableColumnHeadings parameter as described here: https://technet.microsoft.com/en-us/library/jj821991(v=sc.20).aspx

    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

    • Marked as answer by janhoedt Saturday, April 25, 2015 7:37 PM
    Friday, April 24, 2015 11:59 AM
  • That does work but it only imports 1 computer (the last in my list).

    Import-CMComputerInformation -CollectionName "All Systems" -FileName "c:\computers2.csv" -EnableColumnHeadings $True -verbose

    csv

    Name,Mac Address
    test123,00:11:22:33:44:55
    test3456,00:11:22:33:44:55
    test75689,00:11:22:33:44:55
    test899,00:11:22:33:44:55
    test756689,00:11:22:33:44:55

    Only test756689 is imported.

    This is the verbose output:

    VERBOSE: Start: Execution of WQL query: SELECT * FROM SMS_Collection WHERE CollectionType = 2 AND Name='All Systems' ORDER by Name
    VERBOSE: Query options: None
    VERBOSE: Performing the operation "Import" on target "ComputerInformation: c:\computers2.csv".
    VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
    VERBOSE: Input properties:
    VERBOSE: -- :: NetBiosName == test123
    VERBOSE: -- :: SMBIOSGUID ==
    VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
    VERBOSE: -- :: OverwriteExistingRecord == True
    VERBOSE: Output properties:
    VERBOSE: -- :: MachineExists == True
    VERBOSE: -- :: ResourceID == 16791724
    VERBOSE: -- :: ReturnValue == 0
    VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
    VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
    VERBOSE: Input properties:
    VERBOSE: -- :: NetBiosName == test3456
    VERBOSE: -- :: SMBIOSGUID ==
    VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
    VERBOSE: -- :: OverwriteExistingRecord == True
    VERBOSE: Output properties:
    VERBOSE: -- :: MachineExists == True
    VERBOSE: -- :: ResourceID == 16791724
    VERBOSE: -- :: ReturnValue == 0
    VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
    VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
    VERBOSE: Input properties:
    VERBOSE: -- :: NetBiosName == test75689
    VERBOSE: -- :: SMBIOSGUID ==
    VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
    VERBOSE: -- :: OverwriteExistingRecord == True
    VERBOSE: Output properties:
    VERBOSE: -- :: MachineExists == True
    VERBOSE: -- :: ResourceID == 16791724
    VERBOSE: -- :: ReturnValue == 0
    VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
    VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
    VERBOSE: Input properties:
    VERBOSE: -- :: NetBiosName == test899
    VERBOSE: -- :: SMBIOSGUID ==
    VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
    VERBOSE: -- :: OverwriteExistingRecord == True
    VERBOSE: Output properties:
    VERBOSE: -- :: MachineExists == True
    VERBOSE: -- :: ResourceID == 16791724
    VERBOSE: -- :: ReturnValue == 0
    VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0
    VERBOSE: Executing method 'ImportMachineEntry' against class 'SMS_Site'
    VERBOSE: Input properties:
    VERBOSE: -- :: NetBiosName == test756689
    VERBOSE: -- :: SMBIOSGUID ==
    VERBOSE: -- :: MACAddress == 00:11:22:33:44:55
    VERBOSE: -- :: OverwriteExistingRecord == True
    VERBOSE: Output properties:
    VERBOSE: -- :: MachineExists == True
    VERBOSE: -- :: ResourceID == 16791724
    VERBOSE: -- :: ReturnValue == 0
    VERBOSE: -- :: SMSUniqueIdentifier == GUID:D86BB77F-4F29-4DFA-B8A1-874783E55FC0


    Jan Hoedt

    Friday, April 24, 2015 12:52 PM
  • Hello,

    You need to specify unique MAC addresses for each imported object.


    David Gustafsson

    • Marked as answer by janhoedt Saturday, April 25, 2015 7:36 PM
    Friday, April 24, 2015 1:08 PM
  • How stupid of me. Did a copy paste as a test and didn't pay attention to that.
    Logical indeed but symptom (only last one was entered) was leading me to the wrong conclusions.
    Thanks!

    Jan Hoedt

    Saturday, April 25, 2015 7:36 PM