Is it possible to find all the network shares on a domain using powershell?
I've tried the following:
Get-WmiObject -class Win32_Share -ComputerName test1
It's possible to run a script that will list all shares. It must be run on Windows Server or a computer that has Microsoft RSAT installed.
winrm quickconfig
to allow remote WMI calls.FindAllShares.ps1
#This must be run on a computer that has the ActiveDirectory module installed (eg. Windows Server)
#The module can be installed using the RSAT suite from Microsoft.
Import-Module ActiveDirectory
#To connect to remote computers, the following needs to be run on them:
#winrm quickconfig
#Get all the computers on the domain
$computers = Get-ADComputer -Filter {enabled -eq $true} | select DNSHostName, Name
$skipComputers = @("COMPUTER1", "COMPUTER2") #This is a list of computers to not check
$skipShares = @("ADMIN$", "IPC$")
$allShares = @()
#Loop through all of the computers and ask each for their shares
foreach ($computer in $computers | sort Name)
{
#Write-Host $computer.DNSHostName
if ($skipComputers -contains $computer.Name)
{
#skip these computers
} else
{
#Write-Host $computer.Name
#Get the shares on this computer
$shares = Invoke-Command -Computer $computer.DNSHostName -ScriptBlock {Get-WmiObject -class Win32_Share}
foreach ($share in $shares)
{
#Write-Host $share.Name
if ($skipShares -contains $share.Name)
{
#skip these shares
} else
{
$sharePath = "\\$($computer.Name)\$($share.Name)"
#Write-Host $sharePath
$allShares += $sharePath
}
}
}
}
#Write-host $($allShares -join ";")
Write-host $($allShares | Out-String)