PowerShell for Windows Admins

Apr 2 2010   11:07AM GMT

Shares: Modifying

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

So far we’ve seen how to discover and create shares.  How do we alter a share?

When we created a share we supplied a number of pieces of information:

  1. folder path
  2. name
  3. type – disk share
  4. maximum number of connections
  5. description

The last two and the permissions mask are the ones we want to alter

001
002
003
004
005
006
007
008
009
010
011
012
013
014
function Set-Share {
[CmdletBinding(SupportsShouldProcess=$True)]
param (
    [string]$name,
    [int]$maxcon,
    [string]$desc
)   
    $share = Get-WmiObject -Class Win32_Share -Filter "Name=’$name’" 
    if (!$maxcon){$maxcon = $share.MaximumAllowed }
    if (!$desc){$desc = $share.Description}
   
    $share.SetShareInfo($maxcon, $desc, $null)

}

Use the share name, maximum connections and description as parameters. If either the number of connections or the description is not set we use the current value.

A call to the SetShareInfo method is used to perform the change.  The $null value at the end is the access mask which we will see how to change later.

The function is used like this

Get-Share -name test1 | fl name, maximumallowed, description
Set-Share -name test1 -desc "Changed"
Get-Share -name test1 | fl name, maximumallowed, description

Set-Share -name test1 -maxcon 25
Get-Share -name test1 | fl name, maximumallowed, description

Set-Share -name test1 -maxcon 25 -desc "New Description"
Get-Share -name test1 | fl name, maximumallowed, description

I’ve altered my Get-Share function so that it becomes capable of returning a single share.  I’ll post that change next

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: