Skip to content

Instantly share code, notes, and snippets.

@TheRealNoob
Created March 30, 2017 05:26
Show Gist options
  • Save TheRealNoob/144c31c88a1cb5bc4a7343018be425ea to your computer and use it in GitHub Desktop.
Save TheRealNoob/144c31c88a1cb5bc4a7343018be425ea to your computer and use it in GitHub Desktop.
#Variables
$ComputerList = "$HOME\Desktop\computerlist.txt"
$SaveDestination = "$HOME\Desktop"
#Setup
$ErrorActionPreference = "SilentlyContinue"
#Script
foreach ($ComputerName in (Get-Content $ComputerList))
{
Get-WmiObject -Class Win32_Share -ComputerName "$ComputerName" 2>&1 | Out-Null
if ($? -eq "True")
{
Write-Host Found shares `@ $ComputerName
Get-WmiObject -Class Win32_Share -ComputerName "$ComputerName" | Where-Object { $_.Name -NotLike "*$" } | Where-Object { $_.Path -Like "*:*" } | Format-Table | Out-File $SaveDestination\$ComputerName.txt
}
}
#Remove false positives
Write-Host ""
Write-Host Removing false positives
Get-ChildItem "$SaveDestination" | Where-Object { $_.extension -eq ".txt" } | Where-Object { $_.length -eq 0 } | Remove-Item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment