Question

This is kind of a painful question to ask, but here goes. I'm creating a powershell script to report on filer shares that are on a netapp. I've gotten to the point where I can create my report of all the shares, but what I now want to do is take the array I've created from a CSV output and extract the sharename value. However I want to append in front of this value the servername "\filer\" so that it creates a UNC path.

I'm intending to look at the UNC and use it to generate information on the filer shares. NTFS permissions, path info, etc etc..

Here's the code:

$sharelist = Import-CSV z:\shares.csv
foreach ($item in $sharelist)
{
$sharelist += $item | add-member -name "Filer" -Value "\\<filername>\" -Membertype NoteProperty
}

This is creating an array and then adding a new property to the array to match my UNC info...

I then run a select object to clean up the output:

$sharelist | select-object mountpoint,filer,sharename,description | export-csv Z:\sharereport.csv -NoTypeInformation

This produces a new csv that's nice and organized when I open it in excel.

However now I want to take the objects "filer" and "sharename" and put them together to produce a UNC path as such:

\\<filername>\<sharepath>

I thought perhaps I could use a foreach loop as follows:

foreach ($object in $sharelist.sharename)
{
$object -replace $object,"\\<filer>\" + $object
}

However this doesn't work... I assume there's got to be a few different wants to do this, so I'd appreciate any guidance on this. Simple problem but my powershell is woefully poor (although its getting better).

Also, I'm getting the information on the shares using the Netapp Powershell toolkit to generate the original sharelist array.

Thanks everyone.

Was it helpful?

Solution

Try Join-Path...

foreach ($object in $sharelist) {
    Join-Path \\<filer>\ $object
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top