Hello - iam new to ps, hoping to learn more.
To perform a “scan” for files/folders and registry. I started to create a script…some of the script works(files & folder w/files) but iam struggeling to get the scanning for .exe,.txt,vbs etc. in C$ to work, so far only tested with .txt. and cant seem to get it right - and…also need some pointers on how to check registry. Localy it works, but remotly…hmm,not so much.
I think i have been starring to long at the code and iam not getting anywhere, and i need to ask for some assistance.(and coffee) If you have some pointers on what iam doing wrong i would appriciate that. Please be kind, like i said - iam not a expert.
Write-Host "searching for files......." $serverlist = Get-Content -path "\\share\target.txt" $containers = @("folders", "files") $loks = Get-Content -Path "\\share\folders.txt" $total=@{} $files=@("c:\temp\1.exe", "c:\temp\2.exe","c:\temp\3.exe") foreach ($server in $serverlist) { $sess=New-PSSession -Name $server $reslist=@{} foreach ($lok in $loks){ $res=@{} $inv=Invoke-Command -Session $sess -ScriptBlock {param($param) Test-Path $param} -ArgumentList $lok $res.add($lok, $inv.ToString()) $reslist+=$res } foreach ($file in $files){ $res=@{} $inv=Invoke-Command -Session $sess -ScriptBlock {param($param) Test-Path $param} -ArgumentList $file $res.add($file, $inv.ToString()) $reslist+=$res } $scope=Invoke-Command -Session $sess -ScriptBlock {Get-ChildItem -path c:\ -Include 1.exe, 1.txt, 1.bat, 1.vbs, 1.php } $total.add($server.tostring(),$reslist) } foreach ($target in $total.GetEnumerator()){ foreach($i in $target.value.GetEnumerator()){ write-host ("{0},{1},{2}" -f $target.key,$i.key,$i.Value) #$i #$i.value } } if (!$scope){ write-host "no files found." } return