Using Get-SMBShare to list the shares of a clustered file server

23 views
Skip to first unread message

Mike Leone

unread,
Oct 20, 2025, 2:54:28 PMOct 20
to NTPowershell Mailing List
So I have a clustered file server NT_SAN1, it's got a lot of shares defined. I want to list all of this, ideally remotely, rather than having to run my script directly on NT_SAN1.

So why doesn't this work?

PS Z:\> Get-SmbShare -ScopeName "NT_SAN1.wrk.ads.pha.phila.gov"
Get-SmbShare : No MSFT_SMBShare objects found with property 'ScopeName' equal to 'NT_SAN1.wrk.ads.pha.phila.gov'.  Verify the value of the property and retry.
At line:1 char:1
+ Get-SmbShare -ScopeName "NT_SAN1.wrk.ads.pha.phila.gov"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (NT_SAN1.wrk.ads.pha.phila.gov:String) [Get-SmbShare], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_ScopeName,Get-SmbShare

The HELP for this command clearly seems to indicate that it can be done:

    Example 6: Get shares that are connected to a specific server

    PS C:\>Get-SmbShare -ScopeName "Contoso-FS"
    Name                          ScopeName                     Path                          Description
    ----                          ---------                     ----                          -----------
    I$                            Contoso-FS                    I:\                           Cluster Default Share
    J$                            Contoso-FS                    J:\                           Cluster Default Share
    VMS1                          Contoso-FS                    I:\VMS
    VMS2                          Contoso-FS                    J:\VMS

I know I am using the right host name:

PS Z:\> Resolve-DnsName -Name "NT_SAN1.wrk.ads.pha.phila.gov"

Name                                           Type   TTL   Section    IPAddress
----                                           ----   ---   -------    ---------
NT_SAN1.wrk.ads.pha.phila.gov                  A      1200  Answer     10.64.7.201


So what am I missing here? I mean, sure, there are other ways to get all the shares (wmi, net view, etc), but why doesn't this PowerShell work? I wanna do it only in Powershell, and (hopefully) using just Powershell commands.

Thanks



--

Mike. Leone, <mailto:tur...@mike-leone.com>

PGP Fingerprint: 0AA8 DC47 CB63 AE3F C739 6BF9 9AB4 1EF6 5AA5 BCDF
Photo Gallery: <http://www.flickr.com/photos/mikeleonephotos>

Michael B. Smith

unread,
Oct 20, 2025, 3:35:50 PMOct 20
to ntpowe...@googlegroups.com

I don’t have a FS cluster with shares handy (only CSVs), but does it work if you use the shortname of the cluster?

--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ntpowershell...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ntpowershell/CAHBr%2B%2BgcVEV-V55dJ6_3YghuhrO01HOBRt4r1xET_xQkz0kOtg%40mail.gmail.com.

Mike Leone

unread,
Oct 20, 2025, 3:46:15 PMOct 20
to ntpowe...@googlegroups.com
Nope. Not with short name or FQDN.

PS O:\software\PHA Scripts> get-smbshare -ScopeName "NT_SAN1"
get-smbshare : No MSFT_SMBShare objects found with property 'ScopeName' equal to 'NT_SAN1'.  Verify the value of the property and retry.

At line:1 char:1
+ get-smbshare -ScopeName "NT_SAN1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (NT_SAN1:String) [Get-SmbShare], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_ScopeName,Get-SmbShare

PS O:\software\PHA Scripts> get-smbshare -ScopeName "NT_SAN1.wrk.ads.pha.phila.gov"
get-smbshare : No MSFT_SMBShare objects found with property 'ScopeName' equal to 'NT_SAN1.wrk.ads.pha.phila.gov'.  Verify the value of the property and retry.

At line:1 char:1
+ get-smbshare -ScopeName "NT_SAN1.wrk.ads.pha.phila.gov"

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (NT_SAN1.wrk.ads.pha.phila.gov:String) [Get-SmbShare], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_ScopeName,Get-SmbShare


If I execute the command directly from the cluster, "get-smbshare" works fine, returns all the shares and access info (which is what I want). 
But I'd rather not execute the script directly on the cluster, even with Invoke-Command or Enter-PSSession.

Especially if it should be possible, and the examples shows it. I always figure I'm doing something wrong, or misunderstanding, but I can't see where, in this case ...


Michael B. Smith

unread,
Oct 20, 2025, 3:58:56 PMOct 20
to ntpowe...@googlegroups.com

If you execute it on the cluster, what is the scopename you use? And what is the scopename reported by the command?

Aakash Shah

unread,
Oct 20, 2025, 4:07:18 PMOct 20
to ntpowe...@googlegroups.com

ScopeName doesn’t appear to be the right parameter to target a remote computer (if I’m understanding the original request correctly).  Try something like this:

 

$Shares = Invoke-Command -ComputerName 'NT_SAN1.wrk.ads.pha.phila.gov' -ScriptBlock {Get-SmbShare}

 

-Aakash Shah

Mike Leone

unread,
Oct 20, 2025, 4:22:08 PMOct 20
to NTPowershell Mailing List
I've left for the day, but I did no scope name, just the command. Pretty sure it returned the short name of the file server role of the cluster, the same one I used. 


     

Mike Leone

unread,
Oct 21, 2025, 9:25:02 AMOct 21
to ntpowe...@googlegroups.com
On Mon, Oct 20, 2025 at 4:07 PM Aakash Shah <aakas...@uci.edu> wrote:

ScopeName doesn’t appear to be the right parameter to target a remote computer (if I’m understanding the original request correctly).  Try something like this:


That's not what the get-help seems to indicate;

  Example 6: Get shares that are connected to a specific server

    PS C:\>Get-SmbShare -ScopeName "Contoso-FS"
    Name                          ScopeName                     Path                          Description
    ----                          ---------                     ----                          -----------
    I$                            Contoso-FS                    I:\                           Cluster Default Share
    J$                            Contoso-FS                    J:\                           Cluster Default Share
    VMS1                          Contoso-FS                    I:\VMS
    VMS2                          Contoso-FS                    J:\VMS

    This command retrieves the SMB shares on the computer that are connected to the SMB server named Contoso-FS.

 This is exactly what I am doing, although not o the computer "Contoso-FS". If I was on that computer, I wouldn't need to specify which computer ...


Mike Leone

unread,
Oct 21, 2025, 9:28:06 AMOct 21
to ntpowe...@googlegroups.com
On Mon, Oct 20, 2025 at 3:58 PM Michael B. Smith <mic...@smithcons.com> wrote:

If you execute it on the cluster, what is the scopename you use? And what is the scopename reported by the command?


Executing directly on the node where the file server role is running on the cluster:

PS P:\> get-smbshare


Name                    ScopeName    Path                                                   Description
----                    ---------    ----                                                   -----------
504Accessibility        NT_SAN1      G:\shares\504Accessibility

PS P:\> get-smbshare -ScopeName NT_SAN1


Name                    ScopeName Path                                                   Description
----                    --------- ----                                                   -----------
504Accessibility        NT_SAN1   G:\shares\504Accessibility

So -ScopeName seems to work *only* on the server where the shares are mounted, regardless of what the help example says.

Mike Leone

unread,
Oct 21, 2025, 9:46:09 AMOct 21
to ntpowe...@googlegroups.com
On Mon, Oct 20, 2025 at 4:07 PM Aakash Shah <aakas...@uci.edu> wrote:

ScopeName doesn’t appear to be the right parameter to target a remote computer (if I’m understanding the original request correctly).  Try something like this:

 

$Shares = Invoke-Command -ComputerName 'NT_SAN1.wrk.ads.pha.phila.gov' -ScriptBlock {Get-SmbShare}


OK, so if I do that (use Invoke-Command), how then can I pass it values returned from the earlier call. 
For example, this fails, because the share name is apparently blank:

$ServerName = "NT_SAN1.wrk.ads.pha.phila.gov"
$AllShares = @()
Write-Verbose "Getting share info on $ServerName"
$AllShares = Invoke-Command -ComputerName $Servername -ScriptBlock {Get-SmbShare}

ForEach ($EachShare in $AllShares)
{
$TheShareName = $EachShare.Name

Write-Host "The Share Name = '$TheShareName'"
$ShareProperties = Invoke-Command -ComputerName $Servername -ScriptBlock {Get-Smbshare -Name $TheShareName}

PS O:\software\PHA Scripts> .\Save-The-Shares-V2.PS1
VERBOSE: Getting share info on NT_SAN1.wrk.ads.pha.phila.gov
VERBOSE: Processing
The Share Name                  = '504Accessibility'
Cannot validate argument on parameter 'Name'. The argument is null. Provide a valid value for the argument, and then try running the command again.
    + CategoryInfo          : InvalidData: (:) [Get-SmbShare], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Get-SmbShare
    + PSComputerName        : NT_SAN1.wrk.ads.pha.phila.gov

Do I need to rewrite the whole script block to execute on the target server? If so, I might as well just run the whole script there, and drop the Invoke-Command ...




Mike Leone

unread,
Oct 21, 2025, 10:06:14 AMOct 21
to ntpowe...@googlegroups.com
On Tue, Oct 21, 2025 at 9:45 AM Mike Leone <tur...@mike-leone.com> wrote:


On Mon, Oct 20, 2025 at 4:07 PM Aakash Shah <aakas...@uci.edu> wrote:

ScopeName doesn’t appear to be the right parameter to target a remote computer (if I’m understanding the original request correctly).  Try something like this:

 

$Shares = Invoke-Command -ComputerName 'NT_SAN1.wrk.ads.pha.phila.gov' -ScriptBlock {Get-SmbShare}


OK, so if I do that (use Invoke-Command), how then can I pass it values returned from the earlier call. 

I really must learn to wait to send these responses, until after I've tried everything: LOL

2. Using the $using: Scope Modifier (PowerShell 3.0 and later):
This method provides a more direct way to reference local variables within a remote ScriptBlock. You simply prefix the local variable name with $using:.
Code
$localVariable = "Hello from local!"Invoke-Command -ComputerName "RemoteServer" -ScriptBlock {    Write-Host "Remote says: $using:localVariable"
$AllShares = Invoke-Command -ComputerName $Servername -ScriptBlock {Get-SmbShare}
Write-Verbose "Processing"

ForEach ($EachShare in $AllShares)
{
$TheShareName = $EachShare.Name

Write-Host "The Share Name = '$TheShareName'"

$ShareProperties = Invoke-Command -ComputerName $Servername -ScriptBlock {Get-Smbshare -Name $using:TheShareName}

$TheSharePath = $ShareProperties.Path
Write-Host "The Share Path = '$TheSharePath'"

$ShareAccess = Invoke-Command -ComputerName $Servername -ScriptBlock {Get-SmbShareAccess -name $using:TheShareName}

PS O:\software\PHA Scripts> .\Save-The-Shares-V2.PS1
VERBOSE: Getting share info on NT_SAN1.wrk.ads.pha.phila.gov
VERBOSE: Processing
The Share Name                  = '504Accessibility'
The Share Path                  = 'G:\shares\504Accessibility'
                        ---------
Entry Name                      = '504Accessibility'
EntryAcctname           = 'NT AUTHORITY\Authenticated Users'
EntryAccessControl      = 'Allow'
EntryRight                      = 'Full'
---------------------------------------------------
Entry Name                      = '504Accessibility'
EntryAcctname           = 'PHA.PHILA.GOV\Domain Admins'
EntryAccessControl      = 'Allow'
EntryRight                      = 'Full'
---------------------------------------------------
Hit ENTER to continue:

So now I can remotely query for a list of shares, and their settings (access, etc), so I can re-create them later, if need be.

Progress!


Michael B. Smith

unread,
Oct 21, 2025, 11:22:22 AMOct 21
to ntpowe...@googlegroups.com

Feel free to file a documentation issue. They are paid attention to.

Wright, John M

unread,
Oct 22, 2025, 8:04:43 AMOct 22
to ntpowe...@googlegroups.com

I think you might want:  Get-SmbShare -CimSession "NT_SAN1.wrk.ads.pha.phila.gov"

 

--

John Wright

IT Support Specialist

1800 Old Bluegrass Avenue, Louisville, KY 40215

502.708.9953

Please submit IT requests to Hazelwoo...@bluegrass.org

24 Hour Helpline 1.800.928.8000

  

CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.

 

From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com> On Behalf Of Mike Leone
Sent: Monday, October 20, 2025 2:55 PM
To: NTPowershell Mailing List <ntpowe...@googlegroups.com>
Subject: [ntpowershell] Using Get-SMBShare to list the shares of a clustered file server

 

EXTERNAL EMAIL - This email was sent by a person from outside your organization. Exercise caution when clicking links, opening attachments or taking further action, before validating its authenticity.

Secured by Check Point

--

Reply all
Reply to author
Forward
0 new messages