Monday, 26 October 2015

Functions to Check for Cifs Share Creation, ACL Create, ACL Delete


FUNCTION Check-CreateCifsShare{
  Param([String]$SHARENAME,[String]$SVMNAME,[String]$LOGFILE)
  $a = Get-NcCifsShare -Template
  $a.ShareName = ""
  $a.Path = ""
  $CheckShare = Get-NcCifsShare -Name ("$SHARENAME") -VserverContext $SVMNAME -Attributes $a
  If($CheckShare){ Wr ("Cifs share - $SHARENAME - created on path " + $CheckShare.Path) GREEN; Wr}
  else{ Wr ("FAILED to create share - $SHARENAME") RED -Log $LOGFILE; Wr}
}

FUNCTION Check-CreateCifsACL{
  Param([String]$SHARENAME,[String]$USERGROUP,[String]$PERMISSION,[String]$SVMNAME,[String]$LOGFILE)
  $a = Get-NcCifsShareAcl -Template
  $q = Get-NcCifsShareAcl -Template
  $q.Share       = $SHARENAME
  $q.UserOrGroup = $USERGROUP
  $q.Permission  = $PERMISSION
  $CheckAcl = Get-NcCifsShareAcl -VserverContext $SVMNAME -Attributes $a -Query $q
  If($CheckAcl){ Wr ("Acl created for share - $SHARENAME : UserOrGroup = $USERGROUP, Permission = $PERMISSION") GREEN; Wr}
  else{ Wr ("FAILED to create acl for share - $SHARENAME : UserOrGroup = $USERGROUP, Permission = $PERMISSION") RED -Log $LOGFILE; Wr}    
}

FUNCTION Check-DeleteCifsACL{
  Param([String]$SHARENAME,[String]$USERGROUP,[String]$SVMNAME,[String]$LOGFILE)
  $a = Get-NcCifsShareAcl -Template
  $q = Get-NcCifsShareAcl -Template
  $q.Share       = $SHARENAME
  $q.UserOrGroup = $USERGROUP
  $CheckAcl = Get-NcCifsShareAcl -VserverContext $SVMNAME -Attributes $a -Query $q
  If(!$CheckAcl){ Wr ("Deleted acl for share - $SHARENAME : UserOrGroup = $USERGROUP") GREEN; Wr}
  else{ Wr ("FAILED to delete acl for share - $SHARENAME : UserOrGroup = $USERGROUP") RED -Log $LOGFILE; Wr}   
}

FUNCTION Wr {
  Param([String]$ToDisplay,[String]$Color = "WHITE",[String]$Log)
  If($ToDisplay){ Write-Host $ToDisplay -ForegroundColor $Color -NoNewLine } else { Write-Host }
  If($Log){ $ToDisplay >> $Log }
}


No comments:

Post a Comment