Powershell New-NfsShare Invalid namespace
Asked Answered
Y

1

5

I'm trying to use the New-NfsShare command to create a network share but I keep getting an invalid namespace error. I'm writing almost verbatim from the provided example so I don't get what's wrong.

Example: New-nfsShare -Name "NFSshare01" -Path "C:\shares\NFSshare01"

My Code: New-NfsShare -Name "LABS" -Path "C:\LABS" -Permission readwrite

Anyone know what is going on? I have already imported the NFS Module into Powershell and I even tried creating the directory first incase for some reason the command can't create the item before making a network share. I am using Windows Server 2012 and powershell version 3.0

Yolondayon answered 4/8, 2016 at 15:52 Comment(0)
T
8

I tested on two of my Windows 2012 systems. On the one without the Server for NFS role, I get the same error:

PS C:\> New-NfsShare -Name 'Temp' -Path 'C:\Temp' -Permission readwrite
New-NfsShare : Invalid namespace
At line:1 char:1
+ New-NfsShare -Name 'Temp' -Path 'C:\Temp' -Permission readwrite
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NfsServerTasks:root/Microsoft/..._NfsServerTasks) [New-NfsShare], C
   imException
    + FullyQualifiedErrorId : HRESULT 0x8004100e,New-NfsShare

But on my system with that role installed, it works just fine (executed from an elevated prompt):

PS C:\> New-NfsShare -Name 'Temp' -Path 'C:\Temp' -Permission readwrite

Name                                    Availability                            Path
----                                    ------------                            ----
Temp                                    Standard (not clustered)                C:\Temp

Check to make sure your system has that role enabled:

PS C:\Windows\system32> Get-WindowsFeature | Where-Object { $_.Name -match 'NFS' }

Display Name                                            Name                       Install State
------------                                            ----                       -------------
        [X] Server for NFS                              FS-NFS-Service                 Installed
[ ] Client for NFS                                      NFS-Client                     Available
            [X] Services for Network File System Man... RSAT-NFS-Admin                 Installed
Tyndale answered 5/8, 2016 at 13:13 Comment(3)
Jon: that did it. Thanks. I was unaware that there was a role to install at all. i assumed I just needed to import the module. In the future should I just look for any roles that are related to an imported module and just enable them?Yolondayon
With newer versions of PowerShell you don't even need to explicitly import the module for a cmdlet like that; it will auto-load the module for you (if the module is installed). In regards to whether you should enable the role automatically, that will have to be up to you to determine if that is acceptable or not. You could certainly write code that checks for the Server for NFS role and enables it if not already enabled. It just depends on whether that would be acceptable for your environment.Tyndale
Note: It also required a reboot for me on Windows Server 2012.Apace

© 2022 - 2024 — McMap. All rights reserved.