Quantcast
Viewing all articles
Browse latest Browse all 21975

Create a share folders on remote servers reading from csv file

Hi All,

Today I am using the below script(got from this forum) to create a folder on remote server and then used new-share module to share it

# Path to file share.
$FileSrvPath = "\\Computername\Temp\"

#NetBIOS domain name.
$domain = "domain name"

#Path to list of users.
$Users = Get-Content "path of the input file"

#Loop through array of users.
Foreach ($User in $Users) {

#Create User folder and set permissions if it does not exist
$UserFolder = $FileSrvPath + $User

if(!(Test-Path -Path $UserFolder))
{
new-item $UserFolder -itemtype Directory
# Configure Remote Desktop Users Full Control access
$Identity = $domain + "\" + $user
$AccessControlType = "Allow"
$FileSystemRights = [System.Security.AccessControl.FileSystemRights]"Modify"
$InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
$PropagationFlags = [System.Security.AccessControl.PropagationFlags]::None

# Configure the Access Control object
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule($Identity,$FileSystemRights,$InheritanceFlags,$PropagationFlags,$AccessControlType)

# Retrieve the directory ACL and add a new ACL
$Path = $UserFolder
$acl = Get-Acl $Path
$acl.AddAccessRule($ace)
$acl.SetAccessRuleProtection($false,$false)

# Add the ACL to the directory object
Set-Acl $Path $acl
}
else
{
Write "Directory for $UserName already exist"
}
Get-Acl $UserFolder | Fl
}

With my basic powershell knowledge , I am trying to combine these two into a single script to achive the below requirement

I have a csv file as below:

Fileserver      username

Server1          User1

Server2          User2

Server3          User3

I need a script which will read the above csv file and create a share folder with user name in common path"e:\temp" on all file servers with the sharing permission as everyone full access

ntfs permission as follows : inheritence + user should have modify permission.

any hint much appreciated

 

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>