Get Files List, Send Report, Parallel

Good afternoon,

I am trying to solve the problem and already so tired to look for a solution

You need:
1. Get a list of machines from OU
2. Scan each drive for files
3. Get the mail address of the user from AD to a remote computer
4. Send scan results to the post office box of the user and administrator
5. Run all this in a variety of flow-parallel

Searching I found, Invoke-Parallel
https://gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430

The script works fine if he is looking for files - create a report for a single computer

When the script runs with the list, miracles begin. Come reports only one computer from the list (for the rest does not come), or do not come at any recipients. Also, if you use the file search as C:\* e scan result is duplicated in the report file. If you specify a UNC path \\servername\c$ log files fill the correct data.

Here is what I got and what I have is not working:

$OU = 'ou=test,dc=root,dc=local'
$Throttle = 10
(Get-ADComputer -Filter * -SearchBase $OU).Name | Out-File $env:TEMP\Servers.txt 
$servers = Get-Content $env:TEMP\Servers.txt
Invoke-Parallel -InputObject $servers -Throttle 10 -ScriptBlock {
if($ping = Test-Connection -ComputerName $_ -BufferSize 16 -quiet -count 2) 
{
Try {
Get-WMIObject Win32_LogicalDisk -filter "DriveType = 3" -ComputerName localhost | select DeviceID | %{(Get-ChildItem ($_.DeviceID + '\') -Include *.doc -Recurse -Force -ErrorAction Ignore).FullName} |  Out-File $env:TEMP\$_.txt
$username=((gwmi win32_computersystem -computer $_).UserName -split '\\')[1]
if($user=Get-AdUser $username -properties mail){
   $email=$user.mail
   Send-MailMessage -SmtpServer smtpserver.root.local -to admin@email.com  -Bcc ((Get-AdUser $email -properties mail).mail) -Body $_ -From sender@email.com -Subject $_ -Attachments $env:TEMP\$_.txt
}
else{Send-MailMessage -SmtpServer smtpserver.root.local -to admin@email.com -Body $_ -From sender@email.com -Subject $_ -Attachments $env:TEMP\$_.txt
}
}
Catch {''}
}
}

This one script works, but as soon as I put the variable in a copy of the recipient reports come just for one computer from the list (last on the list). If I do not specify a variable after the search report is generated, the recipient receives all the letters. 

$OU = 'ou=test,dc=root,dc=local'
$Throttle = 10
(Get-ADComputer -Filter * -SearchBase $OU).Name | Out-File $env:TEMP\Servers.txt 
$servers = Get-Content $env:TEMP\Servers.txt
Invoke-Parallel -InputObject $servers -Throttle 10 -ScriptBlock {
if($ping = Test-Connection -ComputerName $_ -BufferSize 16 -quiet -count 2) 
{
Try {
(Get-ChildItem ('\\' + $_ + '\c$') -Include *.doc -Recurse -Force -ErrorAction Ignore).FullName} |  Out-File $env:TEMP\$_.txt
Send-MailMessage -SmtpServer smtpserver.root.local -to admin@email.com  -Body $_ -From sender@email.com -Subject $_ -Attachments $env:TEMP\$_.txt
}
Catch {''}
}

Please help, I have no strength and expertise to cope this task :(



May 25th, 2015 9:18am

You would do better with answers and with understanding if you were to format your code so that it is readable.

Your question is a bit muddled. Try asking one simple question with a small piece of code illustrating your issue.

You need to say what "not working" means.  What are the errors?  Have you tried tracing?

Your script cannot be run remotely because the modules required are noo available remotely.

What is the pupose of connecting to a remote coomoputer and having it ping itself.

I think you need to rethink what you want to do.  A workflow can make it faster but you need to use a workflow and not Invoke-Parallel or use invoke correctly.

Finally you should post questions about how to use a custom repository script to the author here: https://gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430/view/Discussions#content

Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 11:06am

Suggestion:  Start by making your scriptblock work independently against more that just to local system.  You will see what I am referring to.
May 25th, 2015 11:13am

Suggestion:  Start by making your scriptblock work independently against more that just to local system.  You will see what I am ref
Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 7:23pm

Suggestion:  Start by making your scriptblock work independently against more that just to local system.  You will see what I am referring

May 25th, 2015 7:54pm

I thinkyou donot understand how workflow works and I cannot decode what you are posting.

We do not add computers to workflow.  They are automatically added and used. That is what the variable $PSComputerName is all

Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 8:51pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics