I'm currently writing a script to retrieve registry entries from a list of remote servers and export to CSV.
I've got this, which works (I'm goign to clean up the error handling later), but the output isn't quite what I want to produce as it doesn't export nicely to CSV.
$DataList = New-Object System.Collections.ArrayList
foreach ($Target in $ImportData) {
Write-Host "Scanning" $Target.ComputerName ":" -NoNewline
$RegData = Get-RegValue -ComputerName $($Target.ComputerName) -Hive $RegHive -Key $KeyName
if (!$RegData) {
Write-Host "No data found for" $Target.ComputerName
[void]$DataList.Add([PSCustomObject]@{
ComputerName = $Target.ComputerName
Hive ="No Data"
Key = ""
Value = ""
Data = ""
Type = ""
})
} else {
$DataList.Add($RegData)
Write-Host "Done"
}
}
$DataList
The output is as follows:
ComputerName Hive Key Value Data ------------ ---- --- ----- --- SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... AssetNumber 987 SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... BuildDate 04/ SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... iLODefaultPwd NA SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... OwnerContactDetails S G SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... OwnerName MS SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... OwnerPhone 643 SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... PatchAutoManual Aut SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... ServerRole Man SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... ServerType Vir SERVER1 LocalMachine SOFTWARE\CUSTOM\Serv... WarrantyExpires NA Value : Key : Data : Hive : None found Type : ComputerName : SERVER2 SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... buildDate 15/ SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... OperatingSystem Win SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... OwnerContactDetails M/S SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... OwnerName GM SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... OwnerPhone 131 SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... PatchAutoManual - SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... ServerRole SNB SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... ServerType Phy SERVER3 LocalMachine SOFTWARE\CUSTOM\Serv... WarrantyExpires -
I suspect the two object types are different but I don't script much and am having a complete mental block on how to get my custom entry to fit in with the ones retrieved automatically.
Get-RegValuedo? It's not a standard cmdlet.