Skip to content

Instantly share code, notes, and snippets.

@marufeuille
Last active October 2, 2016 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marufeuille/bb3e63a303a7de598cb95d0ff4795a62 to your computer and use it in GitHub Desktop.
Save marufeuille/bb3e63a303a7de598cb95d0ff4795a62 to your computer and use it in GitHub Desktop.
[
{
"SharedName": "Share1",
"SharedDirectoryPath": "E:\\shares1\\",
"PermitAccount": "Everyone",
"Permission": "Full",
"Quota": "500mb",
"VSS": {
"On": "E:",
"Size": "50%"
}
},
{
"SharedName": "Share2",
"SharedDirectoryPath": "E:\\shares2\\",
"PermitAccount": "Everyone",
"Permission": "Full"
},
{
"SharedName": "Share3",
"SharedDirectoryPath": "E:\\shares3\\",
"PermitAccount": "Everyone",
"Permission": "Full",
"Quota": ""
}
]
$scriptRoot = Split-Path (Resolve-Path $myInvocation.MyCommand.Path)
$settings = Get-Content($scriptRoot + "\setting.json") -Raw | ConvertFrom-Json
Import-Module ServerManager
Install-WindowsFeature -Name File-Services,FS-VSS-Agent,FS-Resource-Manager
foreach ($item in $settings) {
# Test Path
if (-not (Test-Path ${item}.SharedDirectoryPath)) {
New-Item ${item}.SharedDirectoryPath -Type Directory
}
if (Get-SmbShare -Name ${item}.SharedName -ErrorAction SilentlyContinue) {
"ShareDir: ${item}.SharedName already exists."
Exit
}
else {
# create SMB sahre
New-SmbShare -Name ${item}.SharedName -Path ${item}.SharedDirectoryPath
}
Grant-SmbShareAccess -Name ${item}.SharedName -AccountName ${item}.PermitAccount -AccessRight ${item}.Permission -Force
# Setup Disk quota.
if ((${item}.Quota -ne $null) -and (${item}.Quota -ne "")) {
$command = "$env:windir\system32\dirquota quota add /path:" + ${item}.SharedDirectoryPath + " /limit:" + ${item}.Quota
& $executionContext.InvokeCommand.NewScriptBlock($command)
}
# Setup VSS
if (${item}.VSS -ne $null) {
$Driveletter = Split-Path ${item}.SharedDirectoryPath -Qualifier
$command = "$env:windir\system32\vssadmin Add ShadowStorage /For=" + ${Driveletter} + " /On=" + ${item}.VSS.On + " /Maxsize=" + ${item}.VSS.Size
& $executionContext.InvokeCommand.NewScriptBlock($command)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment