1515. PARAMETER ServerName
1616 The server name for DFS targets. Default is current computer name.
1717
18+ . PARAMETER ShareAccess
19+ The identity to grant full access on created SMB shares. Default is "Everyone".
20+ Modify to restrict access as needed (e.g., "Domain Users", "DOMAIN\ShareGroup").
21+
1822. PARAMETER LogPath
1923 Path for the log file. Default is "C:\Logs".
2024
3640 Author : Leonardo Klein Rezende
3741 Prerequisite : DFSN PowerShell module, Administrative privileges
3842 Creation Date : 2025-08-10
39-
43+ Version : 1.0.0
44+
4045 Requires:
4146 - Administrative privileges
4247 - DFS Management features installed
4752 https://docs.microsoft.com/en-us/powershell/module/smbshare/
4853#>
4954
55+ [System.Diagnostics.CodeAnalysis.SuppressMessage (' PSReviewUnusedParameter' , ' ShareAccess' ,
56+ Justification = ' Used in New-ShareFolder function scope' )]
57+ [System.Diagnostics.CodeAnalysis.SuppressMessage (' PSReviewUnusedParameter' , ' EnableDebugMode' ,
58+ Justification = ' Used in Write-ScriptLog function scope' )]
5059[CmdletBinding (SupportsShouldProcess )]
51- [System.Diagnostics.CodeAnalysis.SuppressMessage (' PSReviewUnusedParameter' , ' EnableDebugMode' , Justification = ' Used in Write-ScriptLog function scope' )]
5260param (
5361 [Parameter (Mandatory = $false )]
5462 [ValidateScript ({ Test-Path $_ - PathType Container })]
@@ -60,6 +68,9 @@ param (
6068 [Parameter (Mandatory = $false )]
6169 [string ]$ServerName = $env: COMPUTERNAME ,
6270
71+ [Parameter (Mandatory = $false )]
72+ [string ]$ShareAccess = " Everyone" ,
73+
6374 [Parameter (Mandatory = $false )]
6475 [string ]$LogPath = " C:\Logs" ,
6576
@@ -119,7 +130,7 @@ function New-SMBShareSafe {
119130 }
120131
121132 if ($PSCmdlet.ShouldProcess ($Name , " Create SMB share" )) {
122- New-SmbShare - Name $Name - Path $Path - Description $Description - FullAccess " Everyone "
133+ New-SmbShare - Name $Name - Path $Path - Description $Description - FullAccess $ShareAccess
123134 Write-ScriptLog " SMB share '$Name ' created successfully" ' Info'
124135 return $true
125136 }
@@ -188,7 +199,7 @@ try {
188199
189200 $successCount = 0
190201 $failureCount = 0
191- $results = @ ()
202+ $results = [ System.Collections.Generic.List [ PSObject ]]::new ()
192203
193204 foreach ($folder in $folders ) {
194205 $folderName = $folder.Name
@@ -220,13 +231,13 @@ try {
220231 Write-ScriptLog " Failed to process folder '$folderName ': $message " ' Error'
221232 }
222233
223- $results += [PSCustomObject ]@ {
234+ $results.Add ( [PSCustomObject ]@ {
224235 FolderName = $folderName
225236 ShareName = $shareName
226237 FolderPath = $folderPath
227238 Status = $status
228239 Message = $message
229- }
240+ })
230241 }
231242
232243 Write-ScriptLog " Processing completed" ' Info'
0 commit comments