Experts,
I'm very new to powershell and scripting. I'm trying to write a script to search my network for PII; starting with SSN's. I need it to tell me where the files are exactly and I also need to to searh .doc, .xls, etc. Can you tell me where i'm going wrong. Here is what I have been using.
# set file to be tested for, put everything after c:\
# "c:\users\default" is the example path
$filetofind = (Get-Childitem -rec -exclude *.exe, *.dll | ?{ findstr.exe /mprc:. $_.fullname } |select-string "[0-9]{3}[-| ][0-9]{2}[-| ][0-9]{4}")
# Hostnames TXT Location
$hostnamestxt = 'C:\users\michael.obrien\desktop\computers.txt'
#Destination file for Positive Machines
$Positivetxt = 'C:\users\michael.obrien\desktop\positive.txt'
#destination file for Negative Machines
$Negativetxt = 'C:\users\michael.obrien\desktop\negative.txt'
##############################################################
# Begin Executing Script - Do Not Edit Below This Line
##############################################################
$computers = get-content "$hostnamestxt"
write-host "__________________"
write-host "Scanning hostnames for SSN"
write-host "__________________"
foreach($computer in $computers)
{
ping -n 1 $computer >$null
if($lastexitcode -eq 0)
{
if (test-path "\\$computer\C$\$filetofind")
{
out-file -append "C:\users\michael.obrien\desktop\results.txt"
echo "$computer" | Out-File -Append "$positivetxt"
write-host "SSN Present on System"
}
else
{
echo "$computer" | Out-file -append "$negativetxt"
write-host "File Not found on $computer"
}
}}
Thanks,
Michael OBrien