I’ve got the following code to export local account info. When I send my $account collection to export-csv my Username and LastLogin properties get populated with Object information and not the properties I want. Outputting $account to the screen shows the info but it’s bracketed, and I believe that means it’s a collection. When I pipe $user.name to GM it tells me it’s a system.string object but export csv says it’s a collection. (System.DirectoryServices.PropertyValueCollection) I’m missing something here and I’m needing some direction/hints on where to look.
UserName LastLogin PWD Age
{User1} {12/7/2015 7:53:24 AM} 3
{User2} {12/3/2015 11:32:47 AM} 49
{User3} User has never logged in. 0
{User4} {12/7/2015 7:46:01 AM} 39
{User5} User has never logged in. 0
Mark Hammonds,
BINGO! We have a winner, that fixed it. Now I need to know WHY it fixed it so I have a better understanding of what just happened. Any guidance?
Well I put the three fields into one custom object and expanded the property by enclosing it with $() like so $($User.name) that means insert the value not the object. I think you will run into the a lot when trying to add a variable with a property to a sting like so
Out-host “The users user ID is $($User.name)”
i’m not the best person to explain these things as I have only been doing power shell for about 12 weeks
Mark,
As soon as I hit send on my reply I had my epiphany and saw what I did wrong. I had run into this issue back in March of this year and completely forgot what I had to do to correct it. What do you want to bet I’m closer to burning this into my brain now? THANK YOU for the time and knowledge.