PowerShell for Windows Admins

Mar 12 2010   4:06PM GMT

Shares: Creating I



Posted by: Richard Siddaway
Tags:
PowerShell v2
Shares
WMI

we’ve seen a few things we can do with shares – its time to look at creating them. A simple share craetion script will look like this

001
002
003
004
005
006
New-Item -Path c:\ -Name share1 -ItemType Directory
New-Item -Path c:\share1 -Name shareA -ItemType Directory
New-Item -Path c:\share1 -Name shareB -ItemType Directory

$s = [WmiClass]"Win32_Share"
$s.Create("c:\share1", "Test1", 0, $null, "Test share1")

We create some folders in a hierarchy with New-Item and then create an instance of the Win32_Share class using the [WmiClass] type accelerator.

We can then call the create method. The parameters are:

  • folder path
  • share name
  • share type – 0 = disk share
  • maximum connections allowed – $null means unlimited
  • description

This sets default permissions on the share

Technorati Tags: ,

 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: