Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

need help with wrtiing errors to csv file

$
0
0

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

The powershell script below is working partially.

It gets succesfully the NETGUID VALUE from computers online at the time the script is ran, and it 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

# 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 { "`n***Processing GUID setting on $($PSItem.Name)***`n" ($guid = [guid](Get-WmiObject -ComputerName $($PSItem.Name) -Class Win32_ComputerSystemProduct).UUID) $computerName1 = $($PSItem.Name) } Catch { Export-Csv -Path C:\ERRORS\Netbootguid-computers.csv -InputObject $computerName1 -Append # $computerName1 | Export-Csv -Path C:\ERRORS\Netbootguid-computers.csv -InputObject $PSItem.Name -Append # Export-Csv -Path C:\ERRORS\Netbootguid-computers.csv [-NoTypeInformation] -Append } Set-ADComputer -Identity $PSItem.Name -Replace @{ netbootGUID = $guid.ToByteArray() } }



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>