Listing SMB Shares on a Windows Machine

Option 1:

PS C:\Windows\system32> get-WmiObject -class Win32_Share

Name   Path       Description
----   ----       -----------
ADMIN$ C:\Windows Remote Admin
C$     C:\        Default share
D$     D:\        Default share
IPC$              Remote IPC
P$     P:\        Default share

Option 2:

PS C:\Windows\system32> net share
Share name   Resource                        Remark
C$           C:\                             Default share
D$           D:\                             Default share
IPC$                                         Remote IPC
P$           P:\                             Default share
ADMIN$       C:\Windows                      Remote Admin
The command completed successfully.

Option 3:

PS C:\Windows\system32> Get-SmbShare
Get-SmbShare : The term 'Get-SmbShare' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-SmbShare
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-SmbShare:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Typically, File server roles are required for the powershell module to be available on such systems. Run the below command, without the whatif switch to install such roles.

PS C:\Windows\system32> Add-WindowsFeature FS-FileServer,FS-Resource-Manager -whatif
What if: Checking if running in 'WhatIf' Mode.
What if: Performing the operation "Add-WindowsFeature" on target "[File Services] File Server Resource Manager".
What if: Performing the operation "Add-WindowsFeature" on target "[File Services] File Server".
What if: This server may need to be restarted after the installation completes.

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True    Maybe          Success   {}

Other Commands to identify features of localhost

PS C:\Windows\system32> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3

PS C:\Windows\system32> Get-Module -ListAvailable
    Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}
    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest    ADRMS                               {Update-ADRMS, Uninstall-ADRMS, Install-ADRMS}
Manifest    AppLocker                           {Set-AppLockerPolicy, Get-AppLockerPolicy, Test-AppLockerP...
Manifest   1.0        BestPractices                       {Get-BpaModel, Invoke-BpaModel, Get-BpaResult, Set-BpaResult}
Manifest    BitsTransfer                        {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer,...
Manifest    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance,...
Script    ISE                                 {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}
Manifest    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}
Manifest    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...
Manifest    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}
Manifest    Microsoft.PowerShell.LocalAccounts  {Add-LocalGroupMember, Disable-LocalUser, Enable-LocalUser...
Manifest    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...
Script     1.0        Microsoft.PowerShell.ODataUtils     Export-ODataEndpointProxy
Manifest    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...}
Manifest    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}
Manifest    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredS...
Manifest    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEt...
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration,...
Script    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WS...
Binary    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Jo...
Manifest    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}
Manifest    PSWorkflowUtility                   Invoke-AsWorkflow
Manifest    ServerManager                       {Get-WindowsFeature, Add-WindowsFeature, Remove-WindowsFea...
Manifest    SoftwareInventoryLogging            {Get-SilComputer, Get-SilComputerIdentity, Get-SilSoftware...
Manifest    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}
Manifest    WebAdministration                   {Start-WebCommitDelay, Stop-WebCommitDelay, Get-WebConfigu...

    Directory: C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     7.0.5000.0 Microsoft.MonitoringAgent.PowerS... {Checkpoint-WebApplicationMonitoring, Get-WebApplicationMo...

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if(!('Nuget' -in (Get-PackageProvider).Name)){Install-PackageProvider -Name NuGet -MinimumVersion -Force}
Install-Module SmbShare -Force

PS C:\Windows\system32> install-module smbshare
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'smbshare'.
Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\\PSModule.psm1:1772 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Option 4:

PS C:\Windows\system32> Install-Module -Name Find-SMBShare
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

PS C:\Windows\system32> find-smbshare

ComputerName     Status     Total AdminShare               PrinterShare                     NotAdmin NotAdminShare
                            Share                                                           Found
------------     ------     ----- ----------               ------------                     -------- -------------
TESTSERVER0005  Connected  5     {ADMIN$, C$, D$, IPC$...                                  False

Leave a Reply

Your email address will not be published. Required fields are marked *