#first script: need to add import offline pc in csv and test connection every 15 minutes from results.csv and if them online state - copy folder
$pc = (Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(operatingSystem=Windows 10*))" -Searchbase (Get-ADDomain).distinguishedName).count
Write-Host "Personal computers = "$pc;
$complist = (Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))" -Properties name | Sort).name;
foreach ($comp in $complist){
$pingtest = Test-Connection -ComputerName $comp -Quiet -Count 2 -ErrorAction SilentlyContinue
if($pingtest)
{ Write-Host($comp + " is online") -ForegroundColor Green }
else
{ Write-Host($comp + " is offline") -ForegroundColor Red }
$comp |export-csv "$env:USERPROFILE\Desktop\results.csv"
}
#second script
$computername = (Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))" -Properties name | Sort).name;
$sourcefile = "\\WIN-OPCVL1KQ9EF\c$\fusion\*"
foreach ($computer in $computername)
{
$destinationFolder = "\\$computer\c$\fusion"
if (!(Test-Path -path $destinationFolder))
{
New-Item $destinationFolder -Type Directory
}
Copy-Item -Path $sourcefile -Destination $destinationFolder;
Invoke-Command -ComputerName $computer -ScriptBlock {powershell "& 'C:\fusion\fusion.bat'";Remove-Item -Recurse -Force 'C:\fusion\'}
}