PowerShell for Windows Admins

Mar 21 2010   7:22AM GMT

Shares: Creating II

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Now we have seen how to create a share lets extend the script a bit.  This is how a lot of my scripts get developed.  I need to solve a particular problem so I write a script to do that task.  While I’m writing I try to see how I can make the script generic. Sometimes the script is written immediately to solve the generic problem and other times I have to solve the immediate problem and go back to the generic bit later.

function New-Share {
param (
    $s = [WmiClass]"Win32_Share" 
        $s.Create($path, $name, $type, $maxcon, $desc)

We take our earlier script and create a function. This forms part of my module for working with the file system.

I’m creating it as an advanced function so I can use the –whatif parameters later.  The function takes a set of parameters and creates the share.

Its used like this

New-Share -path c:\share1 -name Test1 -type 0 -maxcon $null -desc "Test share 1 from module"

Next stage is to add the code to test the existence of the folder and to check that the share creates properly

Technorati Tags: ,

1  Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • Shares: Creating III - PowerShell for Windows Admins
    [...] https://itknowledgeexchange.techtarget.com/powershell/shares-creating-ii/ [...]
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: