Skip to main content

PowerShell Crypto Guy's weblog

Go Search
Blog-EN
Blog-RU
PS PKI Module
  

Links
Archive
Locations of visitors to this page
PowerShell Crypto Guy's weblog > Posts > Share management in PowerShell
Share management in PowerShell

Surprise, it's me again! Today I have finished network share management module for PowerShell. I want to thank Shay Levy who helped me with module-related stuff.

With this module you will be able to:

  • List share (or shares) from local or from remote computers;
  • Create new share with various settings;
  • Remove share (actually this not remove folder itself, but stops sharing);
  • Add/Set/Remove share permissions (note that share permissions and NTFS rights are not the same).

Here are module installation instructions:

The ZIP file contains the module files only and you need to extract its content to one of two places:

  1. %USERPROFILE%\Documents\WindowsPowerShell\Modules
  2. %WINDIR%\System32\WindowsPowerShell\v1.0\Modules (need admin privileges)
  3. If the directory tree (of one of the above) doesn't exist then you should manually create it.

Check if the module is installed correctly, from your PowerShell session type:

PS C:\> Get-Module -ListAvailable ModuleType Name ExportedCommands ---------- ---- ---------------- Manifest ShareUtils {} PS C:\>

If you don't see the above result then the module was not installed correctly. Make sure the module directory exists under "%USERPROFILE%\Documents\WindowsPowerShell\Modules"

Importing the module:

PS C:\> Import-Module ShareUtils

Note: An elevated PowerShell session is needed to load the module. If the session is not elevated a warning message is written to the console and you won't be able to use any of the module’s functions.

PS C:\> Get-Command -Module shareutils CommandType Name Definition ----------- ---- ---------- Filter Add-SharePermission ... Function Get-Share ... Function New-Share ... Filter Remove-Share ... Filter Remove-SharePermission ... Filter Set-Share ... Filter Set-SharePermission ... PS C:\>

Each function (filter) has its own help. To get a help you may run the following command:

Get-Help <FunctionName>

And download link:

Comments

Great PS utils.

THX for sharing this great utils.

lp,J
at 2010.12.28. 7:37

Coach Boots

How fun! I linked to this on last weekend's weekly roundup and am just now getting around to letting you know. (I guess we were busy celebrating Easter!) Thanks so much for sharing!
at 2011.02.21. 4:47

get-help cannot find help topics

I imported the modules as instructed.  I can see "ShareUtils" under -ListAvailable.  Get-Command -Module ShareUtils does not return and results.  No help listed under Get-Help.  Please-Help!
at 2011.04.25. 19:23

Re: Share management in PowerShell

It looks like you haven't imported it via Import-Module cmdlet.
Vadims Podans at 2011.04.27. 9:01

Re: Share management in PowerShell

Thanks for sharing shareutils.

There's an issue with AllowMaximum (default $true), and MaximumAllowed (default 0). If I leave the default settings in order to allow maximum connection with the share, the script will create the share with 0 allowed connections. (Tested on Windows 7 and Windows Server 2008 R2)

As a workaround I replaced each $ShareInfo.MaximumAllowed with $(if (!($ShareInfo.AllowMaximum)) {$ShareInfo.MaximumAllowed})

But, this approach is not perfect because it's not possible to toggle between allow maximum and allow a fixed number.
at 2012.01.19. 11:16

File Hash Error Encountered When Launching PS Modules

After extracting the zip to its own folder in %WINDIR%\System32\WindowsPowerShell\v1.0\Modules, when I launched 'Windows Powershell Modules' I got the following error:

WARNING: File C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ShareUtils\ShareUtils.psm1 cannot be loaded. The contents of file C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ShareUtils\ShareUtils.psm1 may have been tampered because the hash of the file does not match the hash stored in the digital signature. The script will not execute on the system. Please see "get-help about_signing" for more details..

at 2012.04.21. 22:05

Re: Share management in PowerShell

ditto
at 2012.04.24. 0:30

Re: Share management in PowerShell

This can be due to invalid execution policy. Start elevated PowerShell and type:

Set-ExecutionPolicy RemoteSigned
at 2012.04.24. 8:55

Re: Share management in PowerShell

ditto
at 2012.04.24. 19:06

Re: Share management in PowerShell

Additionally you need to unblock downloaded files (right-click on each and click Unblock in file properties).
at 2012.04.27. 21:04

System Programmer

Does not seem to work on 2008 R2 Cluster Shares.  I created a share called TEST$ and it could not find it when I did a get-share.  Bummer.
at 2012.10.20. 2:54

Re: Share management in PowerShell

Is there any way to accomplish this without WMI? I'm looking for a way to remotely manage shares on a non-Windows NAS storage system. I can use Computer Management MMC to connect to the NAS remotely and manage the shares, but looking for a way to do it without WMI since it's not supported on the NAS.
at 2012.12.11. 1:23

Re: Share management in PowerShell

I'm not aware about other ways.
at 2012.12.11. 8:16

Re: Share management in PowerShell

Is there any way to accomplish this without WMI? I'm looking for a way to remotely manage shares on a non-Windows NAS storage system. I can use Computer Management MMC to connect to the NAS remotely and manage the shares, but looking for a way to do it without WMI since it's not supported on the NAS.
at 2012.12.11. 15:52

Re: Share management in PowerShell

Is there any way to accomplish this without WMI? I'm looking for a way to remotely manage shares on a non-Windows NAS storage system. I can use Computer Management MMC to connect to the NAS remotely and manage the shares, but looking for a way to do it without WMI since it's not supported on the NAS.
at 2012.12.11. 21:52

Max allowed

Can you please fix the code or show the syntax required to allow maximum connections to a share.
at 2013.01.30. 6:19

Re: Share management in PowerShell

Are you sure that new created share do not allow maximum connections?
at 2013.01.30. 21:36

Max Allowed

Yes, I am sure. the default if no entry is put in is 0 so it creates a share with no user access allowed.
at 2013.02.08. 0:23

MaxAllowed fix

In ShareUtils.psm1 change line 46 from "public int MaximumAllowed;" to "public long MaximumAllowed;",and in New-Share.ps1 change line 50 from from "[int]$MaximumAllowed = 0" to "[long]$MaximumAllowed = 4294967295".
This fixed it for me.
at 2013.03.05. 12:52

Re: Share management in PowerShell

The fix for MaximumAllowed above worked great for me as well on a Server 2012. Thanks!
at 2013.10.21. 17:26

Add SharePermission

Im having problems running command Add-SharePermission, could please provide me an example to run this command?
at 2013.10.22. 20:21

Add SharePermission

Im having problems running command Add-SharePermission, could please provide me an example to run this command?
at 2013.10.22. 20:43

Re: Share management in PowerShell

Thanks for sharing this module. Helped me out creating shares on remote servers.
at 2013.11.13. 18:06

Cannot create a network share

Thanks for creating this module, very useful. I have a problem however, I am unable to create a share with the format "\\servername\e$\directory\directory", " sharename$"

No error messages, just doesn't work. If I use a local path, it works fine. I also get the same result if I use the [WMICLASS]”WIN32_Share” method with $ Shares.Create.

Any ideas? thanks for the help

at 2014.01.17. 11:57

Cannot create a network share

Thanks for creating this module, very useful. I have a problem however, I am unable to create a share with the format "\\servername\e$\directory\directory", " sharename$"

No error messages, just doesn't work. If I use a local path, it works fine. I also get the same result if I use the [WMICLASS]”WIN32_Share” method with $ Shares.Create.

Any ideas? thanks for the help

at 2014.01.17. 12:29

thank you thank you

Thank you for this module, it has seriously saved me many of hours of work trying to make this happen in my new user creation script!
at 2014.01.17. 21:10

RE: Cannot create network share

Here's how I create my remote shares, you can try this:

$Alias =<username declared earlier in my script>  

 $server = "<servername>"
 $HomeFolderMasterDir="\\$server\d$\<sharedirectory>\"
 new-item -path $HomeFolderMasterDir -name $Alias -type directory 
at 2014.01.17. 21:13

Re: Share management in PowerShell

-Path parameter expects the *local* path on remote server, not UNC (which is not supported). In your case, the -Path parameter shoud be "d:\<shareddirectory>".
at 2014.01.20. 13:15

not working in 2008 R2 fileover cluster

The get-share cmdlet doesn't show any share using "virtual computer name"
get-share -name "anysharename" -computername "clusterfileservername"
at 2014.01.21. 18:34

Re: Share management in PowerShell

The module (and underlying API) do not support virtual names. Instead, you must specify cluster node names. It is by design.
at 2014.01.22. 11:15

SecurityDescriptor Access type

Parsing a manually created share with a group having FULL rights is listed in the SecurityDescriptor property as Read.

Other than that so far appears to be good.
at 2014.07.01. 11:12

IT Mgr

I see the ModuleType as Script and the only exported command available is Test-ElevatedShell. Im running Win7 client talking to a Win2008r2 server. Is it my environment?
at 2014.07.09. 19:30

Re: Share management in PowerShell

what "Get-Command -Module shareutils" returns?
at 2014.07.14. 13:09

Add Comment

Your name *


Title


Body *


I'm a human intellect: *


Enter any number between 0 and 100.
Attachments