How to Create a Shared Folder using PowerShell

Create a shared folder

Provisioning and managing shared folders through the native Windows process is a pretty straightforward process. However, things can get quickly out of hand when you need to manage multiple shares across multiple computers. With PowerShell, you can carry out the task.
The following script can create a shared folder when provided with the path of the desired folder to be shared and the share name as parameters. Just make sure the folder path exists before running this command.


This script can be used to create a shared folder.
This script can be used to create a shared folder.
C:\PS> C:\Script\Shared_Folder.ps1 C:\Users\gautam\Desktop\testfolder share
Creates a shared folder of name share in path C:\Users\gautam\Desktop .
param ( [string]$Path , [string]$Name )
#If folder is available in the given path shares the folder.
#else NewFolder is created and shared.

if((Test-Path $Path) -eq “true”)
(Get-WmiObject Win32_Share -List).Create($Path, $Name , 0)
New-Item $Path -Type Directory
(Get-WmiObject Win32_Share -List).Create($Path , $Name , 0)
#To show the permissions for the sharedfolder.

$per=Get-WmiObject -Class Win32_Share -Filter “Name=’$Name'”
$per|Get-Acl | Select Path,Owner,Group,AccessToString


    Limited-period offers on our IAM solutions

      • Related Articles

      • Create a mailbox database in Exchange Server

        Manually provisioning mailbox databases to new users can be arduous. However, administrators can turn to PowerShell scripts to create mailbox database easily. The below script will create a mailbox database in an Exchange Server with the name 'D10'. ...
      • Create a ShortCut for an Exe File

        Creating a shortcut to an application on multiple end user desktops can be a laborious task. However, the process is pretty straightforward when using a PowerShell script. In the following script, provide the path of the EXE file and the exact path ...
      • Identifying Active Directory built-in groups

        An Active Directory (AD) environment will contain a set of groups by default when a domain is created. These groups are built-in groups, and they are located in the built-in container. The built-in groups can be used to control access to shared ...
      • Powershell Script to Delete Files Older than X days

        Files and folders can accumulate over time and take up considerable space in the database or hard drives and end up slowing the computer considerably. However, deleting them manually isn't quite scalable. This is where PowerShell scripts can be of ...
      • Creating a custom object in Active Directory

        There may be instances where the objects available in an Active Directory (AD) schema do not suit your organization's requirements. In this case, you can create a custom AD object that suits your organization's needs. This task can be done easily ...