Martin Kirkley

Create a share with PowerShell

Discussion created by Martin Kirkley on Sep 3, 2015

Hi there,


this kind of thing was discussed in the post here: automate cifs share creation using Powershell but I thought I'd make a new one as that post is November 2014. I'm very new to Hitachi storage so I'm hoping that someone can point me in the right direction and let me know what I'm doing wrong here.


I'm trying to create a file share with PowerShell as part of an automated user provision script, but I'm getting an error. I can create the folder, but I cannot share it. I tested the code I'm using against an EMC and it works perfectly so I'm at a loss as to why I'm getting errors when running it against our HNAS.


This is the code that I'm using:




If (!(GET-WMIOBJECT Win32_Share -filter “name='MKirkley2$'”)) {


                Write-Host "Share created!"


else{Write-Host "Share MKirkley2$ already exists!"}


And I get the following result:


__GENUS                        : 2

__CLASS                         : __PARAMETERS

__SUPERCLASS             :

__DYNASTY                    : __PARAMETERS

__RELPATH                     :


__DERIVATION               : {}

__SERVER                        :

__NAMESPACE      :

__PATH           :

ReturnValue                     : 9

PSComputerName   :


Share created!


However, the Share is not created and the Return Value of 9 means: Path not found (9)

I can open Windows Explorer and browse right to the path of the share without any issues at all.


I've tried using the SMB Share commands from Windows 2012 R2 and I get errors there too, but that makes sense.

Get-Smbshare : No MSFT_SMBShare objects found with property 'Name' equal to '\\share_name'.  Verify the value of

the property and retry.

At line:1 char:1

+ Get-Smbshare \\share_name

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (\\share_name:String) [Get-SmbShare], CimJobException

    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_Name,Get-SmbShare


Now if I try this then it works on our EMC and I can list all the shares, but not on the HNAS:
$share = [ADSI]"WinNT://share_name/lanmanserver"



This is the error I get:

format-default : The following exception occurred while retrieving member "distinguishedName": "The RPC server is unavailable.


    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException

    + FullyQualifiedErrorId : CatchFromBaseGetMember,Microsoft.PowerShell.Commands.FormatDefaultCommand



I've tried escaping by doing a .Replace('/','\/') but that doesn't help. Is there something I have to turn on at the HNAS side to enable this kind of connection? How can I create a new share via powershell on an HNAS?


Thank you!