none
Using Set-QADComputer for multiple computers in column A with properties in Column B RRS feed

  • Question

  • Currently using a script to set a property on a single computer works well, but now I have a list I need to set and do not have the time to do it manually for each one. Any help on a foreach and/or loop script would be helpful.

    Single line script: *disregard "property" and "objectprop"

    function set-"Property" {
    $computer= Read-Host "Computer name"
    $"Property" = Read-Host "'Property'"
    Set-QADComputer -Identity $computer -ObjectAttributes @{"objectprop" = $"property"} -Proxy

    Get-QADComputer $computer -IncludedProperties "objectprop" |select name, "objectprop"
    }

    I have an excel file with the computer in 1 column and the corresponding property needing to be set in another column.

    Any help/advice greatly appreciated

    Wednesday, August 21, 2019 4:48 PM

Answers

  • Hi,

    Thanks for your question.

    CSV file example:

    powershell script example:

    Import-Csv -Path "c:\infor.csv" | ForEach-Object { Set-QADComputer -Identity $_.computer -ObjectAttributes @{"objectprop" = $($_.property)} -Proxy}

    Best regards,

    Lee


    Just do it.

    • Marked as answer by Tur3yj1z Thursday, August 22, 2019 1:22 PM
    Thursday, August 22, 2019 7:03 AM
    Moderator

All replies

  • help import-csv -online

    help foreach-object -online


    \_(ツ)_/

    Wednesday, August 21, 2019 4:55 PM
    Moderator
  • Hi,

    Thanks for your question.

    CSV file example:

    powershell script example:

    Import-Csv -Path "c:\infor.csv" | ForEach-Object { Set-QADComputer -Identity $_.computer -ObjectAttributes @{"objectprop" = $($_.property)} -Proxy}

    Best regards,

    Lee


    Just do it.

    • Marked as answer by Tur3yj1z Thursday, August 22, 2019 1:22 PM
    Thursday, August 22, 2019 7:03 AM
    Moderator
  • Thank you. This was perfect
    Thursday, August 22, 2019 1:22 PM