Creating Folder Shares with PowerShell
Here is a cool little function that you can use to create a share on a system. Save this function in a PowerShell module and load to your toolset.To run this cfunction you must have full administrator privileges, this function also sets the ErrorActionPreference to stop.
function New-Share { param($Path, $Name) try { $ErrorActionPreference = 'Stop' if ( (Test-Path $Path) -eq $false) { $null = New-Item -Path $Path -ItemType Directory } net share $Name=$Path } catch { Write-Warning "Create a new share: Failed, $_" } }
To use the new function open up a PowerShell command and type:
PS C:\> New-Share c:\temp TempShare
TempShare was shared successfully.
Now you should be able to see the new share you have created. You will want to go in and set access permissions to the new share you created.
Leave a Reply