Loop csv file data RRS feed

  • Question

  • Hi guys.

    I'm trying add some servers in a SCCM collection using the following command:

    Add-CMDeviceCollectionDirectMembershipRule  -CollectionName "Orchestrator_Colecao_Servidores" -ResourceId $servidorID

    However, only last server of list run successfully.

    Someone knows what can I change in script?

    cd "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
    Import-Module .\ConfigurationManager.psd1
    Set-Location GFM:
    Import-csv "c:\temp\lista_servidores.csv" | foreach {
    $servidor = $_.servidor
    $servidorID=(get-cmdevice -name $servidor).ResourceID
    Add-CMDeviceCollectionDirectMembershipRule  -CollectionName "Orchestrator_Colecao_Servidores" -ResourceId $servidorID

    Thank you!

    David Soares MCTS:MBS - MCTS - MCITP

    Thursday, July 20, 2017 9:51 PM


  • It's more like this:

    $modulepath = 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
    Import-Module $modulepath
    Import-csv c:\temp\lista_servidores.csv |
     	        Write-Host 'SERVIDOR:' $_.servdior
    $device = Get-CmDevice -name $_.servdior Add-CMDeviceCollectionDirectMembershipRule -CollectionName Orchestrator_Colecao_Servidores -ResourceId $device.ResourceID }
    "Servidor" is not spelled "servidior".  Check your file.


    • Edited by jrv Thursday, July 20, 2017 10:09 PM
    • Marked as answer by David S. Araujo Wednesday, August 9, 2017 8:41 PM
    Thursday, July 20, 2017 10:07 PM