Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Invoke installation .bat

$
0
0

Hi all I have a silent install .bat for Construct 2. I need to invoke it on a few machines as a bandage till we put it in SCCM. However I'm sure how to invoke bat files.  I'll paste what I have. Do I need to do it as a process?

$computers = Get-Content 'C:\Users\cody\Desktop\complist.txt'
$date = Get-Date
$result = {"C:\Construct 2\install.bat"}

if(!(Test-Path C:\users\cody\Desktop\fails.txt)){
    New-Item -Path C:\users\cody-horton\Desktop -Name fails.txt –ItemType File
}

foreach($computer in $computers){
    
    if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet)){
        Add-Content -Path C:\users\cody\Desktop\fails.txt -Value "$($computer) Error Connecting"
    }
    else{
        Copy-Item "C:\users\cody\Desktop\Vmware_Files\Construct 2" "\\$($computer)\C`$\" -Recurse
        Invoke-Command -ComputerName $computer -ScriptBlock $result -AsJob
        write-host $computer -ForegroundColor Green

    }

}

Add-Content -Path C:\users\cody\Desktop\fails.txt -Value "Done $($date)"
Thanks!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>