Dead_Eyes
asked on
net share powershell script
Hi I need some help getting a script working, So far the script takes column 2 (location of folder) and column 3 (username) from a .csv file, creates the folder and sets permissions. I also need it to share the folder and set share permissions but after a few failed attempts I admit I can't seem to get the syntax right. The share also needs to be hidden so I need it to add a $ sign at the end of the share name. Line 6 (marked by##) of the script below is all that needs tweaking
$scriptblock = {
param ($arg2, $arg3)
new-item -itemtype directory -path $arg2
#set permissions with $arg3
icacls $arg2 /grant "$($arg3):(OI)(CI)F"
##"net share ",$_,"$","=",($arg2).Path, "\",$_," ""/GRANT:Everyone,FULL"" ""/Unlimited"""
}
$s = New-PsSession -computername server1
Import-Csv "C:\test\test.csv" | ForEach-Object {
Invoke-Command -session $s -ScriptBlock $scriptblock -ArgumentList $_."second", $_."third"
}
$scriptblock = {
param ($arg2, $arg3)
new-item -itemtype directory -path $arg2
#set permissions with $arg3
icacls $arg2 /grant "$($arg3):(OI)(CI)F"
##"net share ",$_,"$","=",($arg2).Path,
}
$s = New-PsSession -computername server1
Import-Csv "C:\test\test.csv" | ForEach-Object {
Invoke-Command -session $s -ScriptBlock $scriptblock -ArgumentList $_."second", $_."third"
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER