ONTAP Discussions

Append additional property to existing cifs share using Powershell

bsnyder27
5,355 Views

Given whatever change occurred between us running 8.3 and now being at Ontap 9.1, we need to add the show_previous_versions property to a number of cifs shares to give users VSS functionality back.

 

Anyone know how to append instead of replace the properties using the Set-NcCifsShare cmdlet for a given cifs share?

1 ACCEPTED SOLUTION

swirlypillow
5,302 Views

I did it like this using a foreach loop, to keep the current set of share properties and just append the "show_previous_versions" property:

 

$results = @()

Connect-NcController -Name $controller -Credential $creds -Verbose

$shares = Get-NcCifsShare -CifsServer $cifsserver

 

$results = $shares|? Path -like "*path_string_here*"|? ShareProperties -NotContains "show_previous_versions"

 

foreach ($result in $results)
     {$change_array = @()
     $change_array = $result.shareproperties + "show_previous_versions"
     Set-NcCifsShare -Name $result.ShareName -ShareProperties $change_array -VS vserver_name_here}

 

Didn't think about using -join "," but that works really well too.

 

Edit: Also, I filtered on a group of CIFS shares that shared a common string in the path that I knew I wanted to isolate, which is why I used the Where-Object -like "*path_string_here*", but you could leave that off and then echo out $results to see what paths do not have "show_previous_versions."  You can also add the -whatif parameter to Set-NcCifsShare to see what would be changed before making the change.

View solution in original post

5 REPLIES 5

JGPSHNTAP
5,327 Views

^^

Start with this one

 

 Set-NcCifsShare

 

 

swirlypillow
5,312 Views

Smiley Frustrated

bsnyder27
5,308 Views

was there more to this comment? 

JGPSHNTAP
5,305 Views

I should have added a little more detail.

 

Most shares are with the default settings.

 

How many shares are outside of the following default settings

 

oplocks, browsable, changenotify, show_previous_versions

 

You can just push all these settings back down by doing a get | set

 

If you have different requirements, you can do stuff like

 

$share = (get-nccifsshare -VserverContext vservername -ShareName data$).shareproperties -join ","

 

That's your current properties of the share,

 

Then you can adjust $share each time and re-write it each time.  Fairly simple

swirlypillow
5,303 Views

I did it like this using a foreach loop, to keep the current set of share properties and just append the "show_previous_versions" property:

 

$results = @()

Connect-NcController -Name $controller -Credential $creds -Verbose

$shares = Get-NcCifsShare -CifsServer $cifsserver

 

$results = $shares|? Path -like "*path_string_here*"|? ShareProperties -NotContains "show_previous_versions"

 

foreach ($result in $results)
     {$change_array = @()
     $change_array = $result.shareproperties + "show_previous_versions"
     Set-NcCifsShare -Name $result.ShareName -ShareProperties $change_array -VS vserver_name_here}

 

Didn't think about using -join "," but that works really well too.

 

Edit: Also, I filtered on a group of CIFS shares that shared a common string in the path that I knew I wanted to isolate, which is why I used the Where-Object -like "*path_string_here*", but you could leave that off and then echo out $results to see what paths do not have "show_previous_versions."  You can also add the -whatif parameter to Set-NcCifsShare to see what would be changed before making the change.

Public