# Connect 2 working scripts in 1 full script please

**URL:** <https://forums.powershell.org/t/connect-2-working-scripts-in-1-full-script-please/17330>\
**Category:** PowerShell Help\
**Created:** [August 18, 2021, 2:46pm UTC](https://forums.powershell.org/t/connect-2-working-scripts-in-1-full-script-please/17330 "2021-08-18T14:46:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shell-guy](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@shell-guy](https://forums.powershell.org/u/shell-guy)\
**Post date:** [August 18, 2021, 2:46pm UTC](https://forums.powershell.org/t/connect-2-working-scripts-in-1-full-script-please/17330/1 "2021-08-18T14:46:54Z")

</div>

#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

```auto
$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\'}
}

```

---

<div class="post-metadata">

**Author:** ![jlogan3o13](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@jlogan3o13](https://forums.powershell.org/u/jlogan3o13)\
**Post date:** [August 19, 2021, 3:13pm UTC](https://forums.powershell.org/t/connect-2-working-scripts-in-1-full-script-please/17330/2 "2021-08-19T15:13:21Z")

</div>

@shell-guy What have you tried on your own, and what issues are you running into? We tend to operate on the “Teach a Man to Fish” motto, and are happy to assist. We usually do not, however, do the work for you.

As a suggestion, once you have the $comp array, you should be able to use it in a For Loop for your second script, just skip exporting it to CSV. Give that a try and let us know if you have issues.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:21pm UTC](https://forums.powershell.org/t/connect-2-working-scripts-in-1-full-script-please/17330/3 "2024-05-16T20:21:58Z")

</div>

Closed on May 16, 2024, 8:21pm UTC


