Create a New Share with PowerShellCreate New Shares with Microsoft PowerShellGuy always like to get the job done. In this case the job is persuading PowerShell to create a network share on an existing folder. Topics for Creating New Shares With PowerShell
♣ Mission to Create a Network ShareI am going to divide this project into three stages. Firstly, enumerate the shares,
secondly, research methods for the WMI class Win32_Share. Finally then create a new
share with PowerShell. Example 1: Preamble, List Existing SharesI have created this script with just one line and two commands. # Microsoft PowerShell script to list shared
folders get-WmiObject -class Win32_Share | sort type, name Note 1: You could use the alias gwmi instead of get-WmiObject. Example 2: Research Win32_Share Methods and DefinitionsIf you are interested in background information, study this example, or else go to example 3. # PowerShell script to Research Win32_Share $objWMI = [wmiClass] 'Win32_share' What this script reveals is that the Win32_Share has a method called create. Furthermore, if you drill down .create has the following detailed definition: Path, Name, Type, MaximumAllowed (connections), Description (comment), Password and Access. To help make sense of this information try a walk-through whereby you create a network share manually in Windows Explorer. Click on the Tools Menu, then Map Network Drive. If you try this technique, then you will see why PowerShell requires a Name and Path. What is less clear is Win32_Share needs a 'Type', just trust me that for our purposes its value is Zero. Else go ahead, create a Share then run this PowerShell share script. Example 3: PowerShell Creates the ShareWe have a slight problem. I cannot see your c:\ drive. The example below creates a network share from the temp folder. However, it would be better, and it would aid your understanding, if you created a folder on your c:\ drive and then amended the value for $FolderPath in my script below. If you are up for another challenge, then edit the value of $ShareName in my script. # Microsoft PowerShell script to create a share $FolderPath = "C:\Temp" Note 1: For simplicity we are only scripting three parameters for Win32_Share, Path, Name and Type. The value for each parameter is held by a corresponding variable, thus each is easy to change. Note 2: I wish I knew more about the line:
Guy Recommends: SolarWinds Engineer's Toolset v10
|
||||||
Download my ebook:
|
*
|
|
|
|
Home Copyright © 1999-2009 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |