I am learing powershell and I need to write the NETBOOTGUID value to computer object attribute field for computers in a given 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.
# Importing AD module
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
Set-ADComputer -Identity $_.SamAccountName -Replace @{ netbootGUID = $guid.ToByteArray() }
Yup, according to the logic you have put, it will iterate for each computers in the group, in the loop it first gets the uuid from your local computer and save it to $guid variable, then sets the guid to the current computer object in the loop. This repeats for each computer but the guid is always from the local computer and is same.
Now I want to add code to it that will sdave to a csv file the names of all computers for which their NetBootGuid attribute were not upgraded becaue the computers were shutdown or for any other reason they could not be reached opn the network at the time the script was ran.
So far I have this, but is not working, any help will be appreaciated, THANKS !
Importing AD module
Import-Module ActiveDirectory
Get all members of the MP-W-Test-Netguid
Get-ADGroupMember ‘MP-W-Test-Netguid’ |
ForEach-Object {
$erroractionpreference = “silentlyContinue”
Try
{
“`nProcessing GUID setting on $($PSItem.Name)`n”
It NOW gets succesfully the NETGUID VALUE from computers online at the time the script is ran, and it NOW WRITES IT succesfully in the netbootguid attribute field.
However, I am having a hard time figuring out how to write to a csv file the names of computers which netbootguids were not written because the computers were inaccesible at the time the script ran. Here is the code. Can you help ? Thanks