Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Installing .MSU Via Powershell & PSexec

$
0
0

Hey Peter

First am sorry for the late reply and I want to thank you really for your great help I’ve tried the second script you wrote and it didn’t work as I wanted. The idea of extracting the package and using the DISM is brilliant but again it just worked on one computer. The only change i’ve made to your script I removed the restart option. After I ran the script it copied the “$Hotfix_64Bit” to both (x86 -x64) machines and it works perfectly fine on the (x64) machine and install the update and all working fine. On the other hand with the (x86) machine nothing has been installed because it copied the wrong file which was “Hotfix_64Bit” and surely couldn’t be installed on the “32Bit” machine. However I sorted it out with the PSEXEC I managed to make it work properly and it worked on both of the machines and it did copy the right files as well on each architecture plus it had a successful installation for the update.



#Variables
$Computers = Get-Content "F:\WindowsManagementFramework4.0\Computer Lists\test list.txt"
$HotFix_32bit = "F:\WindowsManagementFramework4.0\Update\Windows6.1-KB2819745-x86-MultiPkg.msu"
$HotFix_64bit = "F:\WindowsManagementFramework4.0\Update\Windows6.1-KB2819745-x64-MultiPkg.msu"
$BatchFile_32bit = "F:\WindowsManagementFramework4.0\Update\WUSA-32Bit.cmd"
$BatchFile_64bit = "F:\WindowsManagementFramework4.0\Update\WUSA-64Bit.cmd"

foreach ($computer in $Computers)

            #### Checking the OS Architecture for the Machines ####
$OSArch = (Get-WmiObject -Class Win32_Operatingsystem -ComputerName $computer).OSArchitecture

if ($OSArch -eq "64-bit")
    ### Copying the Batch file and the Update Package ###
{
New-Item \\$computer\c$\Update -ItemType directory
Copy-Item $HotFix_64bit -Destination \\$computer\C$\Update
Copy-Item $BatchFile_64bit -Destination \\$computer\C$\Update

       #### Using the PSEXEC to excute the .cmd file on the Remote machine #### 
    & set-alias psexec "F:\WindowsManagementFramework4.0\PSTools\PSEXEC.exe"
psexec 2> $null -i -s \\$Computer cmd /c "c:\Update\wusa-64bit.cmd"
     } 
      else
{
New-Item \\$computer\c$\Update -ItemType directory
Copy-Item $HotFix_32bit -Destination \\$computer\C$\Update
Copy-Item $BatchFile_32bit -Destination \\$computer\C$\Update

    & set-alias psexec "F:\WindowsManagementFramework4.0\PSTools\PSEXEC.exe"
psexec 2> $null -i -s \\$Computer cmd /c "c:\Update\wusa-32bit.cmd"
        }
    }

I am trying to add the cmdlet “Test-Connection” to test the connection before it hits the machine to copy the files plus logging all of this actions on the script I tried to add this part of the “Test-Connection”


#Variables
$Computers = Get-Content "F:\WindowsManagementFramework4.0\Computer Lists\Computers.txt"
$HotFix_32bit = "F:\WindowsManagementFramework4.0\Update\Windows6.1-KB2819745-x86-MultiPkg.msu"
$HotFix_64bit = "F:\WindowsManagementFramework4.0\Update\Windows6.1-KB2819745-x64-MultiPkg.msu"
$BatchFile_32bit = "F:\WindowsManagementFramework4.0\Update\WUSA-32Bit.cmd"
$BatchFile_64bit = "F:\WindowsManagementFramework4.0\Update\WUSA-64Bit.cmd"

foreach ($computer in $Computers)

   ###### Checking the connection to the machines ######
    {
$Connection = Test-Connection -ComputerName $Computer -Quiet -Count 1 | Out-File -FilePath F:\Script-Log.txt
    
     if ($Connection -eq "True") 

{Write-Host "$Computer is Online"} Else {
Write-Host "$Computer is Offline"}
    }

So I’ve tested it separately and it did work perfectly on the testing side but it didn’t log anything in the “Script-Log.txt” file. What I found in the .txt after the script has been finished was 1 single entry which was true that was it :). I will be so thankful if I can get any help about that.


Viewing all articles
Browse latest Browse all 13067

Trending Articles