Cdelchapo
Cdelchapo

Reputation: 1

Installl .exe app to remote computers - Powershell

I've been slamming my head against the wall with this one.

EXPECTED:

WHAT IS ACTUALLY DOING:

SERVERS.txt - Contains w/o spaces USER01 DC01 EX01

$computers = Get-Content c:\software\servers.txt
$sourcefile = "\\dc01\software\install\AcrobatDC.exe"

foreach ($computer in $computers){
$destinationfolder = "\\$computer\C$\temp\"

if (!(Test-Path -Path $destinationfolder -Credential $domaincredentials)) 
{ 
New-Item $destinationfolder -Type Directory -Credential 
$domaincredentials
    }
    }

    Copy-Item -Path $sourcefile -Destination $destinationfolder -Credential 
$domaincredentials

    Invoke-Command -cn $computer -Credential $domaincredentials -ScriptBlock 
{Powershell.exe C:\temp\AcrobatDC.exe /sAll /msi /norestart ALLUSERS=1 
EULA_ACCEPT=YES}

Upvotes: 0

Views: 62

Answers (1)

Theo
Theo

Reputation: 61208

Your main problem comes from bad indentation of the code. Because of that, it is hard to notice that you are performing the Copy-Item and Invoke-Command lines outside the foreach loop.

I didn't test the actual scriptblock for the adobe install, but I think you may also change that.

Try

$computers  = Get-Content -Path 'c:\software\servers.txt'
$sourcefile = "\\dc01\software\install\AcrobatDC.exe"

foreach ($computer in $computers){
    $destinationfolder = "\\$computer\C$\Temp"

    if (!(Test-Path -Path $destinationfolder -Credential $domaincredentials)) { 
        New-Item $destinationfolder -Type Directory -Credential $domaincredentials
    }
    Copy-Item -Path $sourcefile -Destination $destinationfolder -Credential $domaincredentials

    Invoke-Command -ComputerName $computer -Credential $domaincredentials -ScriptBlock { 
        & 'C:\temp\AcrobatDC.exe' "/sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YES"
    }
}

Upvotes: 1

Related Questions