PowerShell – install Visual Studio Code

The next part of silent install series scripts – Visual Studio Code.

#madeBy krai.be
#-------------[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\VSCode\'
$destination='c$\scripts\install\VSCode\'
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\VSCode\VSCodeSetup-x64-1.23.0.exe /VERYSILENT /NORESTART /LOADINF="c:\scripts\install\VSCode\VSCode.inf"'}}
            
            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
    }
}

where file: VSCode.inf (in the same directory as the installation) looks like:

[Setup]
NoIcons=0
Tasks=desktopicon,addcontextmenufiles,addcontextmenufolders,associatewithfiles,addtopath

Leave a Reply

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