Microsoft Virtualization Discussions

Set-NaCifsShareAcl and Get-NaCifsShareAcl property names

MAGENTRY
4,032 Views

I'm new to PowerShell and still trying to understand how everything fits together.

I noticed these two cmdlets use a different property for the CIFS share name - "Share" vs. "Sharename".  Is this type of thing commonly "fixed" or have I misinterpreted this being done in error? 

I was attempting to write a PowerShell statement to retrieve all the shares on a filer with "everyone / Full Control" and replace that with "Authenticated Users / Full Control".  I ended up doing it like this -

Get-NaCifsShareAcl | Where-Object {$_.UserAclInfo -like "everyone"} | Select-Object @{Name="Share";Expression={$_."ShareName"}} | Set-NaCifsShareAcl -User "NT AUTHORITY\Authenticated Users" -AccessRights "Full Control"

Get-NaCifsShareAcl | Where-Object {$_.UserAclInfo -like "everyone"} | Select-Object @{Name="Share";Expression={$_."ShareName"}} | Remove-NaCifsShareAcl -User "everyone"

Is there an easier way to do this?  Usually it seems like the pipes work somewhat magically but in this case the magic disappeared and I had to remap the property names manually.

2 REPLIES 2

sizemore
4,032 Views

Hey Matthew,

While we try to keep those parameter names the same there are instances where it makes sense to change them.  However in those instances we should always have an alias set on the parameter that does that mapping for you.  For instance if we check the set-nacifsshareacl cmdlet, the Share parameter will bind to either Name, or ShareName.

PS ≥ Get-NaHelpAlias set-nacifsshareacl

Name                                                        Aliases
----                                                        -------
Share                                                       {ShareName, Name}
User                                                        {Username}
UnixGroup                                                   {Groupname}
AccessRights                                                {}
Acl                                                         {}
Controller                                                  {Filer, Server}
Verbose                                                     {vb}
Debug                                                       {db}
ErrorAction                                                 {ea}
WarningAction                                               {wa}
ErrorVariable                                               {ev}
WarningVariable                                             {wv}
OutVariable                                                 {ov}
OutBuffer                                                   {ob}
WhatIf                                                      {wi}
Confirm                                                     {cf}

In other words you could just do:

Get-NaCifsShareAcl | Where-Object {$_.UserAclInfo -like "everyone"} | Set-NaCifsShareAcl -User "NT AUTHORITY\Authenticated Users" -AccessRights "Full Control"

Get-NaCifsShareAcl | Where-Object {$_.UserAclInfo -like "everyone"} | Remove-NaCifsShareAcl -User "everyone"

Hope that helps,

~Glenn

MAGENTRY
4,032 Views

Thanks Glenn!  I wasn't aware of the aliases and apparently I overcomplicated things a bit.  This is very helpful, thanks for taking the time to reply!

-Matt

Public