<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add and Modify CIFS User Directory Permissions Error in Software Development Kit (SDK) and API Discussions</title>
    <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/137025#M2525</link>
    <description>&lt;P&gt;Hello &lt;a href="https://community.netapp.com/t5/user/viewprofilepage/user-id/30993"&gt;@hyunminlee&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have the context around how this function is being used, so I can't really test it to verify that it's working correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function ConnectSecurityNaDirectoryII {
    param(
        [String]$UserName,
        [String]$DomainUserName,
        [String]$FullVolumeUser,
        [String]$NaUser,
        [String]$NaPassWord,
        [String]$IPAddress,
        [String]$VServer,
        [String]$ModulePath
    )
    Begin {

        Import-Module DataONTAP

        # no need to wrap the username and passwords in quotes to convert them to
        # strings.  PoSh will do this automatically.
        $username = $NaUser
        $password = $NaPassWord

        # no need for the ToCharArray call.  See this URL for more ways to do auth:
        # https://practical-admin.com/blog/netapp-powershell-toolkit-authentication/
        $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
        $cred = New-Object System.Management.Automation.PSCredential $username,$securePassword

        # connect to the controller
        Connect-NcController $IPAddress -Credential $cred -Vserver $VServer
    }
    Process {
        
        $User = $UserName
        $Account = $DomainUserName
        $Path = $FullVolumeUser.Substring(4,$FullVolumeUser.Length-4)

        # create the directory
        New-NcFileDirectorySecurityNtfs -SecurityDescriptor $User -VserverContext $VServer
        
        # remove the default permissions
        Get-NcFileDirectorySecurityNtfsDacl -SecurityDescriptor $User -VserverContext $VServer | Remove-NcFileDirectorySecurityNtfsDacl

        # add custom permissions
        Add-NcFileDirectorySecurityNtfsDacl -SecurityDescriptor $User -Account $Account -AccessType Allow -Rights Full_Control -VserverContext $VServer
        Add-NcFileDirectorySecurityPolicyTask -Name $User -path $Path -SecurityType ntfs -VserverContext $VServer -NtfsSecurityDescriptor $User
        Set-NcFileDirectorySecurity -Name $User -VserverContext $VServer

        Remove-NcFileDirectorySecurityPolicy -Name $User -VserverContext $VServer
        Remove-NcFileDirectorySecurityNtfs -SecurityDescriptor $User -VserverContext $VServer

    }
    End {
        # remove the stored controller
        $Global:CurrentNcController = $null
    }
}&lt;/PRE&gt;&lt;P&gt;I made some changes to the function, in particular using the Begin, Process, and End methods for pipeline processing.&amp;nbsp; These apply when using the pipeline to execute the same function multiple times.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$users = @("a", "b", "c")

$users | Do-MyCustomFunction&lt;/PRE&gt;&lt;P&gt;When this is executed, the PowerShell pipeline will execute the Begin section once (at the start), then each iteration (for each element of the $users array) will execute the Process section, with the End section being executed once as the final thing before going on to the next step in the pipeline.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is very important when doing resource (and time) intensive operations like loading a module and connecting to the ONTAP controller.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which brings me to my first question: why bother loading the module and then connecting + disconnecting from the cluster as a part of the function?&amp;nbsp; Presumably this is called as a part of a larger script, why not have the Import-Module and Connect-NcController functionality outside of the function so that the function only needs the relevant information?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All of that being said, and regardless of the above, how are you executing your function?&amp;nbsp; Can you give me the code (or a snippet) for the script which executes the function?&amp;nbsp; That may help to determine why variables from the previous loop iteration are not being reset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jan 2018 20:53:30 GMT</pubDate>
    <dc:creator>asulliva</dc:creator>
    <dc:date>2018-01-02T20:53:30Z</dc:date>
    <item>
      <title>Add and Modify CIFS User Directory Permissions Error</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/136995#M2523</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Add and modify CIFS user-specific directories.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Problem with the information of the pre-progressed user being added to the next user's progress&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;function ConnectSecurityNaDirectoryII{&lt;BR /&gt;param(&lt;BR /&gt;[String]$UserName,&lt;BR /&gt;[String]$DomainUserName,&lt;BR /&gt;[String]$FullVolumeUser,&lt;BR /&gt;[String]$NaUser,&lt;BR /&gt;[String]$NaPassWord,&lt;BR /&gt;[String]$IPAddress,&lt;BR /&gt;[String]$VServer,&lt;BR /&gt;[String]$ModulePath&lt;BR /&gt;)&lt;BR /&gt;$username = &amp;amp;quot;$NaUser&amp;amp;quot;&lt;BR /&gt;$password = &amp;amp;quot;$NaPassWord&amp;amp;quot;&lt;BR /&gt;$secstr = New-Object -TypeName System.Security.SecureString&lt;BR /&gt;$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}&lt;BR /&gt;$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr&lt;/P&gt;&lt;P&gt;import-module $ModulePath&lt;/P&gt;&lt;P&gt;Connect-NcController $IPAddress -cred $cred -vserver $VServer&lt;/P&gt;&lt;P&gt;$User = $UserName&lt;BR /&gt;$Account = $DomainUserName&lt;BR /&gt;$Path = $FullVolumeUser.Substring(4,$FullVolumeUser.Length-4)&lt;/P&gt;&lt;P&gt;New-NcFileDirectorySecurityNtfs -SecurityDescriptor $User -VserverContext vs01&lt;BR /&gt;Get-NcFileDirectorySecurityNtfsDacl -SecurityDescriptor $User -VserverContext vs01 | Remove-NcFileDirectorySecurityNtfsDacl&lt;BR /&gt;Add-NcFileDirectorySecurityNtfsDacl -SecurityDescriptor $User -Account $Account -AccessType Allow -Rights Full_Control -VserverContext vs01&lt;BR /&gt;Add-NcFileDirectorySecurityPolicyTask -Name $User -path $Path -SecurityType ntfs -VserverContext vs01 -NtfsSecurityDescriptor $User&lt;BR /&gt;Set-NcFileDirectorySecurity -Name $User -VserverContext vs01&lt;/P&gt;&lt;P&gt;Remove-NcFileDirectorySecurityPolicy -Name $User -VserverContext vs01&lt;BR /&gt;Remove-NcFileDirectorySecurityNtfs -SecurityDescriptor $User -VserverContext vs01&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#세션종료&lt;BR /&gt;$Global:CurrentNcController = $null&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 14:11:43 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/136995#M2523</guid>
      <dc:creator>hyunminlee</dc:creator>
      <dc:date>2025-06-04T14:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Modify CIFS User Directory Permissions Error</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/137025#M2525</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.netapp.com/t5/user/viewprofilepage/user-id/30993"&gt;@hyunminlee&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have the context around how this function is being used, so I can't really test it to verify that it's working correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function ConnectSecurityNaDirectoryII {
    param(
        [String]$UserName,
        [String]$DomainUserName,
        [String]$FullVolumeUser,
        [String]$NaUser,
        [String]$NaPassWord,
        [String]$IPAddress,
        [String]$VServer,
        [String]$ModulePath
    )
    Begin {

        Import-Module DataONTAP

        # no need to wrap the username and passwords in quotes to convert them to
        # strings.  PoSh will do this automatically.
        $username = $NaUser
        $password = $NaPassWord

        # no need for the ToCharArray call.  See this URL for more ways to do auth:
        # https://practical-admin.com/blog/netapp-powershell-toolkit-authentication/
        $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
        $cred = New-Object System.Management.Automation.PSCredential $username,$securePassword

        # connect to the controller
        Connect-NcController $IPAddress -Credential $cred -Vserver $VServer
    }
    Process {
        
        $User = $UserName
        $Account = $DomainUserName
        $Path = $FullVolumeUser.Substring(4,$FullVolumeUser.Length-4)

        # create the directory
        New-NcFileDirectorySecurityNtfs -SecurityDescriptor $User -VserverContext $VServer
        
        # remove the default permissions
        Get-NcFileDirectorySecurityNtfsDacl -SecurityDescriptor $User -VserverContext $VServer | Remove-NcFileDirectorySecurityNtfsDacl

        # add custom permissions
        Add-NcFileDirectorySecurityNtfsDacl -SecurityDescriptor $User -Account $Account -AccessType Allow -Rights Full_Control -VserverContext $VServer
        Add-NcFileDirectorySecurityPolicyTask -Name $User -path $Path -SecurityType ntfs -VserverContext $VServer -NtfsSecurityDescriptor $User
        Set-NcFileDirectorySecurity -Name $User -VserverContext $VServer

        Remove-NcFileDirectorySecurityPolicy -Name $User -VserverContext $VServer
        Remove-NcFileDirectorySecurityNtfs -SecurityDescriptor $User -VserverContext $VServer

    }
    End {
        # remove the stored controller
        $Global:CurrentNcController = $null
    }
}&lt;/PRE&gt;&lt;P&gt;I made some changes to the function, in particular using the Begin, Process, and End methods for pipeline processing.&amp;nbsp; These apply when using the pipeline to execute the same function multiple times.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$users = @("a", "b", "c")

$users | Do-MyCustomFunction&lt;/PRE&gt;&lt;P&gt;When this is executed, the PowerShell pipeline will execute the Begin section once (at the start), then each iteration (for each element of the $users array) will execute the Process section, with the End section being executed once as the final thing before going on to the next step in the pipeline.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is very important when doing resource (and time) intensive operations like loading a module and connecting to the ONTAP controller.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which brings me to my first question: why bother loading the module and then connecting + disconnecting from the cluster as a part of the function?&amp;nbsp; Presumably this is called as a part of a larger script, why not have the Import-Module and Connect-NcController functionality outside of the function so that the function only needs the relevant information?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All of that being said, and regardless of the above, how are you executing your function?&amp;nbsp; Can you give me the code (or a snippet) for the script which executes the function?&amp;nbsp; That may help to determine why variables from the previous loop iteration are not being reset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2018 20:53:30 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/137025#M2525</guid>
      <dc:creator>asulliva</dc:creator>
      <dc:date>2018-01-02T20:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add and Modify CIFS User Directory Permissions Error</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/137028#M2526</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Is there a way to log through the corresponding powershall execution within storage?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 06:26:03 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Add-and-Modify-CIFS-User-Directory-Permissions-Error/m-p/137028#M2526</guid>
      <dc:creator>hyunminlee</dc:creator>
      <dc:date>2018-01-03T06:26:03Z</dc:date>
    </item>
  </channel>
</rss>

