Friday, July 26, 2024
HomePowershellListing all Community Shares from all Home windows Servers – SID-500.COM

Listing all Community Shares from all Home windows Servers – SID-500.COM


PowerShell

In at the moment’s weblog publish I present the best way to retrieve all community shares from all servers in an Energetic Listing area to get a pleasant record within the output. This script is used to doc your Energetic Listing surroundings. Let’s get began.

Retrieve all Server by Title

Initially, we have to retrieve the server names.

# Retrieve Server Names 
$server = Get-ADComputer -Filter 'operatingsystem -like "*server*"' | Choose-Object -ExpandProperty Title

Brief evaluate.

Nice!

Retrieving all Share Names of all Servers

Now the occasion begins. Since we’ve got all of the server names, we are able to use Invoke-Command and Get-SmbShare to retrieve all of the shares.

# Assortment Level 
$outcome = @()

# Present all Shares of all Servers
foreach ($s in $server) {
    $shares = Invoke-Command -ComputerName $s -ScriptBlock  Choose-Object PSComputerName,Title,Path 
    $outcome += New-Object PSObject -Property ([ordered]@{ 
        ServerName  = $s
        Shares      = $shares.Title -join "`n"
        Path        = $shares.Path -join "`n"
    })
}
Write-Output $outcome | Format-Desk -AutoSize -Wrap

Hope this was useful. Have a pleasant day.

Printed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2023], IT-Coach, IT-Guide, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments