Creating SMB Shares Remotely

by Jun 8, 2017

Here are a couple of lines that remotely create an SMB share on a server:

#requires -Version 3.0 -Modules CimCmdlets, SmbShare -RunAsAdministrator
$computername = 'Server12'
$shareName = 'ScriptExchange'
$fullAccess = 'domain\groupName'

$session = New-CimSession -ComputerName $computername
New-SMBShare -Name $shareName -Path c:\Scripts -FullAccess $fullAccess -CimSession $session
Remove-CimSession -CimSession $session

You can then map a network drive to that share from your client. Note that network shares are per user, so when you map it with your Administrator account, it is not accessible in Windows Explorer.

$computername = 'Server12'
$shareName = 'ScriptExchange'
net use * "\\$computername\$shareName"

Twitter This Tip! ReTweet this Tip!