locked
Writing NETGUID value to computer object attribute field for computers in group (using Powershell) RRS feed

  • Question

  • I am learning powershell and I need to write the NETBOOTGUID value to computer object attribute field for computers in a given AD group.

    The pwersheelscript below is working partially.

    It gets succesfully the NETGUID VALUE from computers online at the time the script is ran, but is writing the SAME NETBOOTGUID value   on all computers on the given group.

     

    So I suspect my code is wrong somewhere in the ForEach-Object.  Can anyone help? Thanks.


    Import-Module ActiveDirectory

    # Get all members of the MP-W-Test-Netguid

      Get-ADGroupMember 'MP-W-Test-Netguid' |
        # Loop through each object


       ForEach-Object {
            # Do this for each member

     # $guid = [guid](Get-WmiObject Win32_ComputerSystemProduct).UUID

      $guid = [guid](Get-CimInstance -Classname Win32_ComputerSystemProduct).UUID 

    Set-ADComputer -Identity $_.SamAccountName -Replace @{ netbootGUID = $guid.ToByteArray() }

    }
    Thursday, May 16, 2019 9:05 PM

Answers

  • You don't need to import AD as it will do this automatically.

    Get-ADGroupMember 'MP-W-Test-Netguid' |
        ForEach-Object {
            $guid = [guid](Get-CimInstance Win32_ComputerSystemProduct -ComputerName $_.Name).UUID
            Set-ADComputer $_.Name -Replace @{ netbootGUID = $guid.ToByteArray() }
        }

    You also need to specify the computer name in all commands.


    \_(ツ)_/



    • Edited by jrv Thursday, May 16, 2019 9:47 PM
    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 3:22 PM
    Thursday, May 16, 2019 9:46 PM
  • The command works correctly on all of my systems.

    To test just run the single command:

    Get-CimInstance Win32_ComputerSystemProduct -ComputerName <remote pc name>


    \_(ツ)_/

    Friday, May 17, 2019 12:26 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 3:23 PM
    Monday, May 20, 2019 6:18 AM
  • I resolved it as this:

    # Importing AD module
    Import-Module ActiveDirectory

    # Get all members of the MP-W-Test-Netguid
    Get-ADGroupMember 'MP-W-Test-Netguid' |
    ForEach-Object {
        "`n***Processing GUID setting on $($PSItem.Name)***`n"
        ($guid = [guid](Get-WmiObject -ComputerName $($PSItem.Name) -Class Win32_ComputerSystemProduct).UUID)
        Set-ADComputer -Identity $PSItem.Name -Replace @{ netbootGUID = $guid.ToByteArray() }
    }

    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 3:26 PM
    Tuesday, May 21, 2019 3:26 PM
  • I resolved it with this code:

    # Importing AD module
    Import-Module ActiveDirectory

    # Get all members of the MP-W-Test-Netguid
    Get-ADGroupMember 'MP-W-Test-Netguid' |
    ForEach-Object {
        "`n***Processing GUID setting on $($PSItem.Name)***`n"
        ($guid = [guid](Get-WmiObject -ComputerName $($PSItem.Name) -Class Win32_ComputerSystemProduct).UUID)
        Set-ADComputer -Identity $PSItem.Name -Replace @{ netbootGUID = $guid.ToByteArray() }
    }

    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 5:05 PM
    Tuesday, May 21, 2019 5:05 PM

All replies

  • You don't need to import AD as it will do this automatically.

    Get-ADGroupMember 'MP-W-Test-Netguid' |
        ForEach-Object {
            $guid = [guid](Get-CimInstance Win32_ComputerSystemProduct -ComputerName $_.Name).UUID
            Set-ADComputer $_.Name -Replace @{ netbootGUID = $guid.ToByteArray() }
        }

    You also need to specify the computer name in all commands.


    \_(ツ)_/



    • Edited by jrv Thursday, May 16, 2019 9:47 PM
    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 3:22 PM
    Thursday, May 16, 2019 9:46 PM
  • When I run the above I get these errors:

    Get-CimInstance : The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP server that does 

    not support the WS-Management protocol.
    At line:3 char:24
    + ... id = [guid](Get-CimInstance Win32_ComputerSystemProduct -ComputerName ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ConnectionError: (root\cimv2:Win32_ComputerSystemProduct:String) [Get-CimInstance], CimException
        + FullyQualifiedErrorId : HRESULT 0x80338113,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
        + PSComputerName        : MPM-IS64-71
     
    Cannot convert null to type "System.Guid".
    At line:3 char:9
    +         $guid = [guid](Get-CimInstance Win32_ComputerSystemProduct -C ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
        + FullyQualifiedErrorId : nullToObjectInvalidCast

    Thursday, May 16, 2019 10:18 PM
  • That is likely due to the remote firewall not allowing the connection.  You will need to solve connectivity issues before you can use this code.

    Also you will need to decide what error management you need.  What if a computer is not online? 

    To program requires that you think about all contingencies and understand all technologies that you want to use.


    \_(ツ)_/

    Thursday, May 16, 2019 10:52 PM
  • Thanks for the reply and advice. I am learning as I go.

    I have been running succesfully other powershell scripts that access computers succesfully on the same network using some of those same commands.

    Thursday, May 16, 2019 11:51 PM
  • The command works correctly on all of my systems.

    To test just run the single command:

    Get-CimInstance Win32_ComputerSystemProduct -ComputerName <remote pc name>


    \_(ツ)_/

    Friday, May 17, 2019 12:26 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 3:23 PM
    Monday, May 20, 2019 6:18 AM
  • Sorry, for the late response.  This fixed it,  THANKS !!
    Tuesday, May 21, 2019 3:22 PM
  • I resolved it as this:

    # Importing AD module
    Import-Module ActiveDirectory

    # Get all members of the MP-W-Test-Netguid
    Get-ADGroupMember 'MP-W-Test-Netguid' |
    ForEach-Object {
        "`n***Processing GUID setting on $($PSItem.Name)***`n"
        ($guid = [guid](Get-WmiObject -ComputerName $($PSItem.Name) -Class Win32_ComputerSystemProduct).UUID)
        Set-ADComputer -Identity $PSItem.Name -Replace @{ netbootGUID = $guid.ToByteArray() }
    }

    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 3:26 PM
    Tuesday, May 21, 2019 3:26 PM
  • I resolved it with this code:

    # Importing AD module
    Import-Module ActiveDirectory

    # Get all members of the MP-W-Test-Netguid
    Get-ADGroupMember 'MP-W-Test-Netguid' |
    ForEach-Object {
        "`n***Processing GUID setting on $($PSItem.Name)***`n"
        ($guid = [guid](Get-WmiObject -ComputerName $($PSItem.Name) -Class Win32_ComputerSystemProduct).UUID)
        Set-ADComputer -Identity $PSItem.Name -Replace @{ netbootGUID = $guid.ToByteArray() }
    }

    • Marked as answer by Alfredvelez Tuesday, May 21, 2019 5:05 PM
    Tuesday, May 21, 2019 5:05 PM