Celerra Powershell Example

[powershell] # CreateLocker.ps1
#
# Powershell script that does the following:
# Asks for dept and locker names
# Creates a folder: \\$server\adminshares\$dept-$name
# Creates a share pointing to the folder named adm-$dept-$name$ (second $ is to hide the share) with share permissions of everyone:full
# Creates a group called COEDEAN-ADM-$dept-$name under NCSU\COE\COEDEAN\Access Groups
# Creates a dfs link for \\wolftech.ad.ncsu.edu\engr\coedean\Admin\$dept\$name pointing at \\$server\adm-$dept-$name$
# Change permissions on the \\$server\adminshares\$dept-$name folder to add->COEDEAN-ADM-$dept-$name:full control

# Equivalent of ‘on error resume next’ in vbscript
# VBS->PS info: http://technet.microsoft.com/en-us/library/ee692947.aspx
$erroractionpreference = “SilentlyContinue”

# Ask for info
Clear
$dept = Read-Host “Enter Dept Name”
Clear
$locker = Read-Host “Enter Locker Name”
Clear

# Constants!
$shortname = “$dept-$locker”
$share = “adm-$shortname$”
$server = “engr90f.eos.ncsu.edu”
$serverNetbios = “engr90f”

# Create AD Group
# Creating basic AD objects: http://blogs.msdn.com/arulk/archive/2006/07/25/678137.aspx
$objOU = [ADSI]”LDAP://OU=Access Groups,OU=COEDEAN,OU=COE,OU=NCSU,dc=wolftech,dc=ad,dc=ncsu,dc=edu”
$group = “COEDEAN-ADM-$shortname”
$objGroup = $objOU.Create(“group”, “cn=$group”)
$objGroup.Put(“sAMAccountName”, “$group”)
$objGroup.Put(“Description”, “Control Access to the $share share on $server”)
$objGroup.SetInfo()

Start-Sleep -s 15

# Create Directory and Set Permissions
# Using the New-Item Cmdlet: http://technet.microsoft.com/en-us/library/ee176914.aspx
# FileSystemAccessRule Constructor: http://msdn.microsoft.com/en-us/library/sfe70whw.aspx
# More FileSystemAccessRule: http://www.vistax64.com/powershell/27540-set-folder-permissions-apply-onto-level.html
$path = “\\$server\AdminShares\$shortname”
New-Item $path -type directory
$Acl = Get-Acl “$path”
$Inherit=[System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$Prop=[System.Security.AccessControl.PropagationFlags]::None
$Ar = New-Object system.security.accesscontrol.filesystemaccessrule(“wolftech.ad.ncsu.edu\COEDEAN-ADM-$shortname”,”FullControl”,$Inherit,$Prop,”Allow”)
$Acl.SetAccessRule($Ar)
Set-Acl “$path” $Acl

Start-Sleep -s 15

# Create Share using WinNT since Celerra doesn’t support WMI
# Info on ADSI WinNT Provider: http://msdn.microsoft.com/en-us/library/aa772211(v=VS.85).aspx
# VBS Examples include share creation: http://www.apostate.com/wsh-adsi-recipes
$Localpath = “C:\ENGR-File-New\shares\AdminShares\$shortname”
$ServerObj = [adsi] “WinNT://$serverNetbios/lanmanserver”
$newshareobj = $ServerObj.create(“fileshare”,$share)
$newshareobj.put(“path”,$Localpath)
#$newshareobj.put(“Description”,$Description)
$newshareobj.setinfo()

Start-Sleep -s 15

# Create DFS Link
# Create Method of the Win32_DFSNode Class: http://msdn.microsoft.com/en-us/library/aa389387(VS.85).aspx
$dfsnode = [wmiclass]”\\.\root\cimv2:win32_dfsnode”
$dfsnode.Create(“\\wolftech.ad.ncsu.edu\engr\coedean\Admin\$dept\$locker”, “\\$server”, “$share”)

[/powershell]