Hey Guys Am one of the Newbies to PowerShell I really love it but I am having some problems with writing my first script and I’d love to have a hand from the expertise in here.
I am trying to install one of Microsoft updates which is the “Windows Management Framework4.0” which we can’t install via WSUS. The update extension is .MSU so am trying to write a script which gonna copy the update and a batch file I’ve created to the remote machines. The batch file will trigger the .MSU file on the remote machine using the PSexec via the Powershell gonna execute the batch file to run the update. The problem is we have different architecture and I tried to include that in the script but for some reason it doesn’t work properly.
#Variables
$Computers = Get-Content -Path “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”
$BatchDest = “\$computer\C$\Update”
$Connection = Test-Connection -Cn $Computer -quiet
foreach ($Computer in $Computers)
{{
$OSArch = (Get-WMIObject -ComputerName $Computer win32_operatingSystem -ErrorAction Stop).OSArchitecture
}
####### Checking the Archetiture and Copying files ########
if ($OSArch -like “64-bit”)
{
New-Item $BatchDest -type directory
Copy-Item $HotFix_64bit -Destination $BatchDest
Copy-Item $BatchFile_64bit -Destination $BatchDest
}
########### Testing Connection and Installing Update ############
if ($Connection -like “True” -and $OSArch -like “64-bit”)
{
& set-alias psexec “F:\WindowsManagementFramework4.0\PSTools\PSEXEC.exe”
psexec 2> $null -i -s \$Computer cmd /c “c:\update\wusa-64bit.cmd”
} else {
“$Computer is not online”
}
if ($OSArch -like “32-bit”)
{
New-Item $BatchDest -type directory
Copy-Item $HotFix_32bit -Destination $BatchDest
Copy-Item $HotFix_32bit -Destination $BatchDest
}
########### Testing Connection and Installing Update ############
if ($Connection -like “True” -and $OSArch -like “32-bit”)
{
& set-alias psexec “F:\WindowsManagementFramework4.0\PSTools\PSEXEC.exe”
psexec 2> $null -i -s \$Computer cmd /c “c:\update\wusa-32bit.cmd”
} else {
“$Computer is not online”
}
}
And this is the outcome when I run this script and by the way the folder doesn’t exist on the remote machine but i’d love to know how to overwrite even if it’s there. The other thin is that the script copied to the laptop which is the x86 and ignored the other desktop x64 eventhough it was online and I was remoting into it.
PS C:> #Variables
$Computers = Get-Content -Path “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”
$BatchDest = “\$computer\C$\Update”
$Connection = Test-Connection -Cn $Computer -quiet
foreach ($Computer in $Computers)
{{
$OSArch = (Get-WMIObject -ComputerName $Computer win32_operatingSystem -ErrorAction Stop).OSArchitecture
}
####### Checking the Archetiture and Copying files ########
if ($OSArch -like “64-bit”)
{
New-Item $BatchDest -type directory
Copy-Item $HotFix_64bit -Destination $BatchDest
Copy-Item $BatchFile_64bit -Destination $BatchDest
}
########### Testing Connection and Installing Update ############
if ($Connection -like “True” -and $OSArch -like “64-bit”)
{
& set-alias psexec “F:\WindowsManagementFramework4.0\PSTools\PSEXEC.exe”
psexec 2> $null -i -s \$Computer cmd /c “c:\update\wusa-64bit.cmd”
} else {
“$Computer is not online”
}
if ($OSArch -like “32-bit”)
{
New-Item $BatchDest -type directory
Copy-Item $HotFix_32bit -Destination $BatchDest
Copy-Item $HotFix_32bit -Destination $BatchDest
}
########### Testing Connection and Installing Update ############
if ($Connection -like “True” -and $OSArch -like “32-bit”)
{
& set-alias psexec “F:\WindowsManagementFramework4.0\PSTools\PSEXEC.exe”
psexec 2> $null -i -s \$Computer cmd /c “c:\update\wusa-32bit.cmd”
} else {
“$Computer is not online”
}
}
$OSArch = (Get-WMIObject -ComputerName $Computer win32_operatingSystem -ErrorAction Stop).OSArchitecture
Dell19550 is not online
Directory: \\Delllap16010\C$
Mode LastWriteTime Length Name
d---- 5/05/2014 4:50 PM Update
$OSArch = (Get-WMIObject -ComputerName $Computer win32_operatingSystem -ErrorAction Stop).OSArchitecture
Delllap16010 is not online
New-Item : Item with specified name \Delllap16010\C$\Update already exists.
At line:41 char:1
- New-Item $BatchDest -type directory
-
+ CategoryInfo : ResourceExists: (\\Delllap16010\C$\Update:String) [New-Item], IOException + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand
PS C:>