troubleshooting Question

Powershell Custom Object Properties Basics Question

Avatar of rookie_b
rookie_b asked on
PowershellWindows OS
3 Comments1 Solution15 ViewsLast Modified:
I often come across a situation where I need an extra property in the object, and I understand one of the ways to create a note property is to use select-object, rather than add-member, or pscustomobject. My problem is I keep getting an error when I try to set that property, that the property doesn't exist or cannot be set, so clearly I am getting  something basic wrong.

For example, I would like to include the path to an acl object access export, but keep getting an error:

$paths = "\\server\share\folder1","\\server\share\folder2","\\server\share\folder3"

$report = @()
$paths |

foreach-object {
$access =  (get-acl $_).access |select-object *,path
$access.path = $_
$report+=$access
}

$report | export-csv -path report.csv -NoTypeInformation


I can use custom object  to achieve that, but I was hoping to save myself some time writing out hash tables by instead using select-object to define the custom property .
Do I need to use new-object?

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros