Scan the network for non-admin file shares

Posted: March 21, 2011 in File Operations, Networking, Scripts

Scans through a bunch of IP ranges looking for machines that respond to ping. Then enumerates all non-adminsitratvie shares and outputs to a file. It tries to resolve the IP to a hostname, if that fails, just uses the IP. Written to cater for /24 IP blocks. You could tweak the looping parameters for any other type of range.

Remove-Item C:\Scripts\FSTest\Shares.txt

$CompanyServerIPRanges = @(“10.1.1″,”10.1.2″,”10.1.3″,”10.1.4”)

foreach ($Range in $CompanyServerIPRanges){

$IPs = 1..254 | %{“$Range.$_”}
ForEach ($IP in $IPs){
& ping -n 1 $IP
$Ping = $?
if ($Ping -eq $True){
$AllFileShares = Get-WmiObject Win32_Share -computerName $IP |Where-Object {$_.Type -le 1}
If ($? -eq $True){
$HostEntry = [System.Net.Dns]::gethostentry($IP)
If ($HostEntry){
$ServerName = $HostEntry.Hostname
$ServerName = $IP
ForEach ($Item in $allFileShares){
If ($Item.Name -ne $null){
“\\” + $ServerName + “\” + $Item.Name | Out-File C:\Scripts\FSTest\Shares.txt -Append



  1. mike says:

    I am new to scripts… How do i run this script? VBS, Bat, wsf? I coped and pasted into notepad and then saved it as .vbs file. Errors out with MS VBScript compilation error. Invalid charecter, line1, char 13, code: 800a0408

    • dthomo says:

      Hi Mike,

      All my scripts are PowerShell. PowerShell 2 is part of the Windows Management Framework, which can be downloaded here:

      Before you can run custom scripts like this one, you will need to open the PowerShell console and run:

      Set-ExecutionPolicy RemoteSigned

      Then save your file as a .ps1 and launch from the PowerShell console. Eg:

      PS C:\Documents and Settings\dthompson\My Documents> .\MyScript.ps1
      This is my script
      PS C:\Documents and Settings\dthompson\My Documents>

      Hope that helps.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s