Sample Script for Creating a VHD File Share and Assigning Permissions

Sample Script for Creating a VHD File Share and Assigning Permissions

To be annotated later.
=====================================================
Param(
    [string]
    $HyperVClusterName,
    [string]
    $ShareName
)

# Check values
if(!$HyperVClusterName -or !$ShareName)
{
    Write-Host "Error: Please enter required parameter values."
    Exit
}

# Create the share folder
MD C:\ClusterStorage\Volume1\$ShareName

# HyperV Nodes
ICACLS.EXE C:\ClusterStorage\Volume1\$ShareName  --% /Grant hcp\HC2N1$:(CI)(OI)F
ICACLS.EXE C:\ClusterStorage\Volume1\$ShareName  --% /Grant hcp\HC2N2$:(CI)(OI)F

# HyperV Cluster Account
$cmdString = "ICACLS.EXE C:\ClusterStorage\Volume1\$ShareName  --% /Grant hcp\$HyperVClusterName"
$cmdString += '$:(CI)(OI)F'
Invoke-Expression -Command $cmdString

# HyperV Admins
ICACLS.EXE C:\ClusterStorage\Volume1\$ShareName  --% /Grant "hcp\Domain Admins:(CI)(OI)F"

# Management group (optional)
ICACLS.EXE C:\ClusterStorage\Volume1\$ShareName  --% /Grant "hcp\SMBShare:(CI)(OI)F"

# Remove inheritance (optional)
ICACLS.EXE C:\ClusterStorage\Volume1\$ShareName  /Inheritance:R

# Create new share and set matching Share permissions
$FullAccess = ('hcp\HC2N1$','hcp\HC2N2$','hcp\domain admins')
$FullAccess += "hcp\$HyperVClusterName" + '$'
New-SmbShare -Name $ShareName -Path C:\ClusterStorage\Volume1\$ShareName  -FullAccess $FullAccess
=====================================================

Leave a Comment
  • Please add 2 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 2. Comment: Removed (en-US) from title, added tag

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Richard Mueller edited Revision 2. Comment: Removed (en-US) from title, added tag

Page 1 of 1 (1 items)