search
top

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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top
Life of a Geek Admin
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.