Skip to content

Instantly share code, notes, and snippets.

@ScriptAutomate
Last active August 29, 2015 14:20
Show Gist options
  • Save ScriptAutomate/2afd203d7686cb3edf17 to your computer and use it in GitHub Desktop.
Save ScriptAutomate/2afd203d7686cb3edf17 to your computer and use it in GitHub Desktop.
Create Shares with PowerShell
break # To prevent accidental example script execution
# Share/NTFS Permissions
$ComputerName = Get-Content c:\temp\serverlist.txt
Invoke-Command -ComputerName $ComputerName -Credential $Credential -ScriptBlock {
# Create the share, give service account permissions
if ((Test-Path "C:\test") -and !(Get-SmbShare test$ -ErrorAction SilentlyContinue)) {
# Creating share
New-SmbShare –Name test$ `
–Path C:\test `
-FullAccess CONTOSO\serviceaccount1 `
-Description "Hidden Test Share"
# NTFS permissions
icacls.exe "C:\test" /grant 'CONTOSO\serviceaccount1:(OI)(CI)(F)' # Give service account full control
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment