Remotely Install Software Using WMI And Powershell

This topic contains 9 replies, has 2 voices, and was last updated by Profile photo of rohan jannu rohan jannu 6 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #36365
    Profile photo of rohan jannu
    rohan jannu
    Participant

    I am newbie in powershell......

    i want to install software over the my network. I got this script from this site in this script i have some issues that was as follow

    1. script can create a folder on remote system but child-items of that source folder can't be copied to remote system.

    2. This script is created for install MSI packages i want to install EXE packages.

    is it possible to do some changes in this script or i am doing something wrong

    $colComputer = Get-Content c:\targets.txt
     
    Foreach ($strComputer in $colComputer) {
     
     $service = Get-Service 'RemoteRegistry' -cn $strComputer
     
     If ($service.Status -match 'Stopped') {
     $service.Start()
     }
     
     #If the target directory doesn't exist, create it
     If (!(Test-Path \\$strComputer\c$\temp\MyInstall\)) {
     mkdir \\$strComputer\c$\temp\MyInstall\
     }
     
     #Get all the files for the setup program. This can be on a network share or your local machine.
     $files = Get-ChildItem "\\path\to\software\"
     
     Foreach ($file in $file) {
     Copy-Item $file.fullname "\\$strComputer\c$\temp\MyInstall\"
     }
     
     #Start the process on the remote machine
     $process = Invoke-WMIMethod win32_process -name create -cn $strComputer -ArgumentList 'msiexec /i "c:\temp\MyInstall\install.msi" /qb /norestart'
     
     #Get the process ID for the newly created process
     $id = $process.processid
     
     #Create a DO WHILE loop to monitor for process exit
     $a = ""
     
     do {
     $a = Get-Process -cn $strComputer | Where{$_.ID -match "$ID"}
     }
     
     While ($a -ne $null)
     
     #Delete the MyInstall directory on the remote machine
     del \\$strComputer\c$\temp\MyInstall -force -recurse
     
     #Lets leave the machine the way we found it in regards to running services
     If ($service.status -match 'Stopped') {
     $service.Stop()
     }
    }
    
    #36380
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    Yes, it could be done. The exe will have to be a silent install. Why not use GPO?

    #36383
    Profile photo of rohan jannu
    rohan jannu
    Participant

    Hello Perez,

    Thanks for the replay...

    what should i need to do for install EXE instead of MSI??

    #36385
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    What exe are you install.
    1. You will need to copy the file the remote machine to a temp file.
    2. You can even create a batch file that has the commands to do a silent install.
    3. once the install has been down you can you WMI to query add and remove apps.
    4. Once you confirm the app has been installed, you can delete the exe files.

    #36388
    Profile photo of rohan jannu
    rohan jannu
    Participant

    i want to install malwarebytes antimalware software over the lan

    ok i will create batch file for the silent installation but how can i call that batch file in powershell??

    is it after running that batch file powershell detect installation complete or not?

    with following script detects application install or not

    #Get the process ID for the newly created process
     $id = $process.processid
     
     #Create a DO WHILE loop to monitor for process exit
     $a = ""
     
     do {
     $a = Get-Process -cn $strComputer | Where{$_.ID -match "$ID"}
     }
     
     While ($a -ne $null)
    

    but what if i call batch file?

    what exactly i need to do could you please make changes in script please

    silent switches as follow

    "mbam-setup-2.2.0.1024.exe" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-

    #36391
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    copy the file to the remote machine using copy -item and the below script will start the install. you will have to change the path. You can also log the installation

    (Start-Process -FilePath C:\Software\mbam-setup-2.2.0.1024.exe -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' -Wait -Passthru).ExitCode
    
    #36392
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    Here is another one with the log created:

    (Start-Process -FilePath C:\Software\mbam-setup-2.2.0.1024.exe -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP- /log=c:\Software\mbamlog.txt' -Wait -Passthru).ExitCode
    

    From the log:

    2016-03-10 12:10:00.727 Creating the icon.
    2016-03-10 12:10:00.732 Successfully created the icon.
    2016-03-10 12:10:00.733 — Icon entry —
    2016-03-10 12:10:00.733 Dest filename: C:\Users\Public\Desktop\Malwarebytes Anti-Malware.lnk
    2016-03-10 12:10:00.734 Creating the icon.
    2016-03-10 12:10:00.739 Successfully created the icon.
    2016-03-10 12:10:00.781 Installation process succeeded. <—- 2016-03-10 12:10:01.243 Need to restart Windows? No 2016-03-10 12:10:01.601 Deinitializing Setup. 2016-03-10 12:10:01.628 Log closed.

    #36430
    Profile photo of rohan jannu
    rohan jannu
    Participant

    ok as you know i am newbie in PS

    could you please tell where i have to past this in my script??

    #36611
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    Do you still need help?

    #37041
    Profile photo of rohan jannu
    rohan jannu
    Participant

    i done some changes to install Lync .EXE format that was as follow......

    $colComputer = Read-Host "Enter Computer Name To Install X86 App"
     
    Foreach ($strComputer in $colComputer) {
     
     $service = Get-Service 'RemoteRegistry' -cn $strComputer
     
     If ($service.Status -match 'Stopped') {
     $service.Start()
     }
    
     If (!(Test-Path \\$strComputer\c$\temp\MyInstall\)) {
     mkdir \\$strComputer\c$\temp\MyInstall\
     }
    
     $file = Get-ChildItem "\\computer02\c$\SoftwareToBeShare\LYNC32"
    
    
     Foreach ($file in $file) {
     Copy-Item $file.fullname "\\$strComputer\c$\temp\MyInstall\LYNC32" -Recurse -Force -Verbose
     }
    
     $process = Invoke-Command -ComputerName $strComputer -ScriptBlock { Start-Process -FilePath C:\temp\MyInstall\LYNC32\setup.exe -Wait -Passthru } 
     
     del \\$strComputer\c$\temp\MyInstall -force -recurse -Verbose
      
     }  
    

    With above script i can install x86 App to computer..............!
    But i dont know how can i get whether setup is completed or not this script
    this script didn't tell about setup is comleted or not...... 🙁 could you please help me regarding this.........................PLEASEEEEEEEEE

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.