hi Script Guy,
I would like to know the how to use LanManServer with Powershell to get share level permissions. And apply share level permissions.
I have the two following powershell script that can create share folder and delete share folder.
function create-share {
param (
[string]$Server = $(Throw "you must specify a server"),
[string]$NewShare = $(Throw "Newshare name is mandatory"),
[string]$Localpath,
[string]$Description
)
$ServerObj = [adsi] "WinNT://$Server/lanmanserver"
$newshareobj = $ServerObj.create("fileshare",$NewShare)
$newshareobj.put("path",$Localpath)
$newshareobj.put("Description",$Description)
$newshareobj.setinfo()
$dummy = [adsi] "WinNT://$Server/lanmanserver/$NewShare"
}
# delete a file share
function delete-share {
param (
[string]$Server = $(Throw "you must specify a server"),
[string]$DeleteShare = $(Throw "deleteshare name is mandatory")
)
$ServerObj = [adsi] "WinNT://$Server/lanmanserver"
$ServerObj.delete("fileshare",$DeleteShare)
$dummy = [adsi] "WinNT://$Server/lanmanserver/$DeleteShare"
}
# use this function to test the argument if it has a value or not
function test ($VALUE) {
if ($VALUE) {
Write-Host -ForegroundColor GREEN “Good”
} else {
Write-Host -ForegroundColor RED “No Good”
}
}