Solved

net share powershell script

Posted on 2014-01-01
4
1,236 Views
Last Modified: 2014-01-05
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"
}
0
Comment
Question by:Dead_Eyes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 350 total points
ID: 39750045
You really should name your parameters in a more appealing way...
$scriptblock = {
    param ($folder, $user)
    new-item -itemtype directory -path $folder
    #set permissions with $user
    icacls $folder /grant "$($user):(OI)(CI)F"
    net share "$(Split-Path $folder -leaf)`$=$folder" '/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"
}

Open in new window

0
 

Author Comment

by:Dead_Eyes
ID: 39750235
Thanks that's great, I am quite new to the param command so naming them arg2 & arg3 just helped me separate any naming association in my head and better understand how it works but thanks for advice when I get my head fully round it I will start naming them better.
0

Featured Post

Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question