Subscribe

Get-nanfsexport SecurityRules -expandproperty

Guys..

I need a little kick-start here.. I'm struggling with the formatting of embedded objects. 

get-nanfsexport has a property security rules that has your readwrite hosts and root access which is yet another embedded object.    I'm just trying to do something what should be basic but I need a little kickstart

pathname  readwrite  root

So, the output i'm looking for would be osmething like

/vol/vol0    all  10.1.2.1

Hence i'm not that good with -expandproperty and multiple embedded objects...

Re: Get-nanfsexport SecurityRules -expandproperty

Would this get you what you are looking for?

foreach ($nfspath in get-nanfsexport){

$customobject = new-object psobject;

$nfs = get-nanfsexport -path $nfspath.ActualPathname | select -ExpandProperty securityrules;

add-member -InputObject $customobject -MemberType NoteProperty -name Path -value $nfspath.Pathname;

add-member -InputObject $customobject -MemberType NoteProperty -name RW -value $nfs.readwrite;

add-member -InputObject $customobject -MemberType NoteProperty -Name Root -value $nfs.root;

$array += $customobject;

}

$array

Re: Get-nanfsexport SecurityRules -expandproperty

That codes not working, but I think your onto something..

I'm hoping beam or clinton chime in on embedded objects.. I'm going to give this another whirl..

Re: Get-nanfsexport SecurityRules -expandproperty

I'm making a little bit of headway on this

PS C:\powershell> get-nanfsexport | select -first 1 | Select pathname, @{N="Root";E={($_.securityrules).root}},@{N="r/w";e={($_.securityrules).readwrite}}

Pathname                                Root                                    r/w

--------                                ----                                    ---

/dump                                   {host1, host2}                 all-hosts

But I still need to figure out how to make that embedded object just a string ..

Re: Get-nanfsexport SecurityRules -expandproperty

Part of the challenge is the result object for Get-NaNfsExport can have zero or more security rules--which are unique.  So we can't just flatten out the object, we have to associate the list of rules with the pathname.  The best was I can think of to do this is using foreach blocks:

PS C:\> Get-NaNfsExport | %{ $path = $_.Pathname; $_.SecurityRules | % { New-Object PSObject -Property @{Pathname=$path; Root = $_.Root; ReadWrite=$_.ReadWrite } } }  | ft Root,ReadWrite -GroupBy Pathname

This formats the result in a table containing Root and ReadWrite, and groups them by the Pathname.  You end up with a table like this:

   Pathname: /vol/dt

Root                                                        ReadWrite

----                                                        ---------

                                                            {all-hosts}

   Pathname: /vol/dt/storagedomain

Root                                                        ReadWrite

----                                                        ---------

{10.61.185.111}                                             {10.61.185.111}

   Pathname: /vol/files

Root                                                        ReadWrite

----                                                        ---------

                                                            {all-hosts}

Now, from here we need to figure out a way to turn that into a string that's readable.  I created a quick little GetString function which will turn that object into a string formatted like so: ({Negate}) {Name}:

function GetString {

param([Parameter(ValueFromPipeline=$true)]$obj)

if($obj -eq $null) { return $null }

return "({0}) {1}" -f $(if($obj.Negate) { "-" } else { "+" }), $(if($obj.AllHosts) { "all-hosts" } else {$obj.Name})

}

Now we can change our original command, and get a new table:

PS C:\> Get-NaNfsExport | %{ $path = $_.Pathname; $_.SecurityRules | % { New-Object PSObject -Property @{Pathname=$path; Root = $_.Root | GetString; ReadWrite=$_.ReadWrite | GetString } } }  | ft Root,ReadWrite -GroupBy Pathname

   Pathname: /vol/dt

Root                                                        ReadWrite

----                                                        ---------

                                                            all-hosts

   Pathname: /vol/dt/storagedomain

Root                                                        ReadWrite

----                                                        ---------

10.61.185.111                                           10.61.185.111

   Pathname: /vol/files

Root                                                        ReadWrite

----                                                        ---------

                                                            all-hosts

I hope that helps!

-Steven

Re: Get-nanfsexport SecurityRules -expandproperty

How about this:

Get-NaNfsExport | select pathname,@{n="RO";e={$_.SecurityRules.ReadOnly -join ','}},@{n="RW";e={$_.SecurityRules.ReadWrite -join ','}},@{n="Root";e={$_.SecurityRules.root -join ','}} | Format-list

I did Format-List for this example but you could Format-Table or export to CSV.  Format-List seems to be a cleaner output than F-T with a long list of IPs but that's probably because I don't know how to expand columns.

OUTPUT:

Pathname : /vol/datastore01

RO       :

RW       : 192.168.102.103,192.168.120.15,192.168.102.105,192.168.120.16,192.168.102.109,192.168.120.18,192.168.102.107,192.168.120.17,192.168.102.7,192.168.99.41,192.168.102.9,192.168.99

           .42,192.168.102.11,192.168.99.43,192.168.102.23,192.168.99.49,192.168.102.25,192.168.99.50,192.168.102.27,192.168.99.51,192.168.102.29,192.168.99.52,192.168.102.13,192.168.99.4

           4,192.168.102.71,192.168.99.77,192.168.102.73,192.168.99.78,192.168.102.75,192.168.99.79,192.168.102.77,192.168.99.80,192.168.102.37,192.168.99.56,192.168.102.15,192.168.99.45,

           192.168.102.17,192.168.99.46,192.168.102.19,192.168.99.47,192.168.102.21,192.168.99.48,192.168.102.31,192.168.99.53,192.168.102.33,192.168.99.54,192.168.102.35,192.168.99.55,17

           2.25.102.79,192.168.99.81,192.168.102.81,192.168.99.82,192.168.102.83,192.168.99.83,192.168.102.85,192.168.99.84,192.168.102.87,192.168.99.85,192.168.102.89,192.168.99.86,172.

           25.102.91,192.168.99.87,192.168.102.93,192.168.99.88,192.168.102.67,192.168.99.73,192.168.102.69,192.168.99.74,192.168.102.95,192.168.99.89,192.168.102.97,192.168.99.90,192.168

           .102.99,192.168.99.91,192.168.102.101,192.168.99.92,192.168.102.39,192.168.99.59,192.168.102.43,192.168.99.61,192.168.102.41,192.168.99.60,192.168.102.47,192.168.99.63,192.168.

           102.49,192.168.99.64,192.168.102.51,192.168.99.65,192.168.102.53,192.168.99.66,192.168.102.45,192.168.99.62,192.168.102.55,192.168.99.67,192.168.102.57,192.168.99.68,192.168.10

           2.59,192.168.99.69,192.168.102.61,192.168.99.70,192.168.102.63,192.168.99.71,192.168.102.65,192.168.99.72

Root     : 192.168.102.103,192.168.120.15,192.168.102.105,192.168.120.16,192.168.102.109,192.168.120.18,192.168.102.107,192.168.120.17,192.168.102.7,192.168.99.41,192.168.102.9,192.168.99

           .42,192.168.102.11,192.168.99.43,192.168.102.23,192.168.99.49,192.168.102.25,192.168.99.50,192.168.102.27,192.168.99.51,192.168.102.29,192.168.99.52,192.168.102.13,192.168.99.4

           4,192.168.102.71,192.168.99.77,192.168.102.73,192.168.99.78,192.168.102.75,192.168.99.79,192.168.102.77,192.168.99.80,192.168.102.37,192.168.99.56,192.168.102.15,192.168.99.45,

           192.168.102.17,192.168.99.46,192.168.102.19,192.168.99.47,192.168.102.21,192.168.99.48,192.168.102.31,192.168.99.53,192.168.102.33,192.168.99.54,192.168.102.35,192.168.99.55,17

           2.25.102.79,192.168.99.81,192.168.102.81,192.168.99.82,192.168.102.83,192.168.99.83,192.168.102.85,192.168.99.84,192.168.102.87,192.168.99.85,192.168.102.89,192.168.99.86,172.

           25.102.91,192.168.99.87,192.168.102.93,192.168.99.88,192.168.102.67,192.168.99.73,192.168.102.69,192.168.99.74,192.168.102.95,192.168.99.89,192.168.102.97,192.168.99.90,192.168

           .102.99,192.168.99.91,192.168.102.101,192.168.99.92,192.168.102.39,192.168.99.59,192.168.102.43,192.168.99.61,192.168.102.41,192.168.99.60,192.168.102.47,192.168.99.63,192.168.

           102.49,192.168.99.64,192.168.102.51,192.168.99.65,192.168.102.53,192.168.99.66,192.168.102.45,192.168.99.62,192.168.102.55,192.168.99.67,192.168.102.57,192.168.99.68,192.168.10

           2.59,192.168.99.69,192.168.102.61,192.168.99.70,192.168.102.63,192.168.99.71,192.168.102.65,192.168.99.72