Custom Objects and Output to a csv file

Hi,

I am using pieces of someone else’s script I came across. The goal of the script is to search AD to see if an account exists. Long story short, my question is about output and objects. In the script, the output to screen for each item is done like this:

if (!($ADResult)) {
$HashProps = @{

‘HomeDir’ = $_.FullName
‘AccountName’ = ‘None’

}

Output the object to the screen

New-Object -TypeName PSCustomObject -Property $HashProps

 

However, I need to put that information into a csv file from within the script. I don’t understand the custom objects, and though I have been researching this, I cannot figure out how to get the result I am looking for. The HomeDir and Accountnames should be headers in a csv file. I want the output to be done in the script.

 

Would someone please help me with this? I would really appreciate it!

just need to pipe the new-object into the export-csv cmdlet (be sure to use the -append parameter to add a new line to the existing file)

$HashProps = @{

HomeDir = 'C:\SomePath'
AccountName = 'OJSimpson'

}

# Output the object to the screen
 New-Object -TypeName PSCustomObject -Property $HashProps | Export-Csv -Path C:\Temp\temp.csv -NoTypeInformation -Append

@bvi1998. While the above reply answers your question, I would like to advice you to take some time to understand the basics in PowerShell. This will help you a lot.
PowerShell in a Month of Lunches by Don Jones is the best book to start with.

yes of course. I was in a pinch.