1

I just want to know all shares on a server, or better all shares in the domain. I was hoping it was possible through a powershell script.

closed as off-topic by mdpc, Ward, kasperd, HBruijn, HopelessN00b Aug 28 '14 at 17:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – Ward, kasperd, HBruijn, HopelessN00b
If this question can be reworded to fit the rules in the help center, please edit the question.

3

If you want to inventorize the shares from all computers in a domain, you could use Get-WmiObject to query the Win32_Share wmi class on each computer:

# Import the AD module to the session
Import-Module ActiveDirectory 
# Retrieve the dNSHostName attribute from all computer accounts in AD
$ComputerNames = Get-ADComputer -Filter * -Properties dNSHostName |Select-Object -ExpandProperty dNSHostName

$AllComputerShares = @()

foreach($Computer in $ComputerNames)
{
    try{
        $Shares = Get-WmiObject -ComputerName $Computer -Class Win32_Share -ErrorAction Stop
        $AllComputerShares += $Shares
    }
    catch{
        Write-Error "Failed to connect retrieve Shares from $Computer"
    }
}

# Select the computername and the name, path and comment of the share and Export
$AllComputerShares |Select-Object -Property PSComputerName,Name,Path,Description |Export-Csv -Path C:\Where\Ever\You\Like.csv -NoTypeInformation
  • Computer is an Object you should use DNSHostName property – SimonOzturk Mar 1 '18 at 0:50
  • @SimonOzturk Already doing so, notice |Select-Object -ExpandProperty dNSHostName – Mathias R. Jessen Mar 1 '18 at 1:26
  • i'm getting a list of AD machines and an error that the Object feeded in Select-Object is null – ndp Apr 5 '18 at 19:49
2

With PowerShell you can use Get-SMBShare.

If you have OS versions that aren't compatible with this cmdlet, you can use good old net share instead.

As for how to run it on each server, you can use Invoke-Command in PowerShell, or psexec from Sysinternals in a command prompt.

Not the answer you're looking for? Browse other questions tagged or ask your own question.