PowerShell – install OpenOffice

PowerShell’ script to remote install Apache OpenOffice.

#-------------[deklarations]--------------------------
#source
$computers=Get-Content '\\host\shares\!scripts\!source\!computers.txt'
#logs
$successLog='\\host\shares\!scripts\!logs\done.LOG'
$errorLog='\\host\shares\!scripts\!logs\error.LOG'
$unreachableLog='\\host\shares\!scripts\!logs\unreachable.LOG'
#params
$source='\\host\shares\!install\openoffice\'
$destination='c$\install\openoffice\'
foreach($computer in $computers) {
    if(Test-Connection -ComputerName $computer -Count 1 -Quiet) {
        Try {
            Write-host "Copying files: $computer" -foreground 'gray'
            Copy-Item -Path $source -Destination \\$computer\$destination -Force -Recurse
            Write-host "Installation: $computer" -foreground 'gray'
            Invoke-Command -computerName $computer -ScriptBlock {powershell.exe 'c:\scripts\install\openoffice\Apache_OpenOffice_4.1.5_Win_x86_install_pl.exe' /S}
            
            Write-host "updated: $computer" -foreground 'green'
            $computer >> $successLog
        } Catch {
            Write-host "error: $computer" -foreground 'red'
            $computer >> $errorLog
        }
    } else {
        Write-host "offline: $computer" -foreground 'yellow'
        $computer >> $unreachableLog
    }
}
#-------------krolaki.eu--------------------------

 

Leave a Reply

Your email address will not be published. Required fields are marked *