Use the Win32_Share Create method. Example:
(Get-WmiObject -List -ComputerName . | Where-Object -FilterScript
{$_.Name -eq "Win32_Share"}).InvokeMethod("Create",
("C:\FolderToShare","ShareName",0,100,"Share description"))
You can find the documentation of this method here on MSDN.
uint32 Create(
[in] string Path,
[in] string Name,
[in] uint32 Type,
[in] uint32 MaximumAllowed,
[in] string Description,
[in] string Password,
[in] Win32_SecurityDescriptor Access
);
Parameters:
- Path - Local path of the Windows share. For example, "C:\FolderToShare".
- Name - Passes the alias to a path set up as a share on a Windows system. Example, "ShareName".
- Type - Passes the type of resource being shared. Types includes disk drives, print queues, interprocess communications (IPC), and general devices. Can be one of the following values.
- 0 - Disk Drive
- 1 - Print Queue
- 2 - Device
- 3 - IPC
- 2147483648 - Disk Drive Admin
- 2147483649 - Print Queue Admin
- 2147483650 - Device Admin
- 2147483651 - IPC Admin
- MaximumAllowed - Limit on the maximum number of users allowed to concurrently use this resource. Example: 100. This parameter is optional.
- Description - Optional comment to describe the resource being shared. This parameter is optional. Example: "Share description".
- Password - Password (when the server is running with share-level security) for the shared resource. If the server is running with user-level security, this parameter is ignored. This parameter is optional.
- Access - Security descriptor for user level permissions. A security descriptor contains information about the permissions, owner, and access capabilities of the resource.
See this page on MSDN for details how to set access permissions: Win32_SecurityDescriptor Class. This article is also a good starting point: WMI Tasks: Files and Folders.