I saw this script on the Microsoft technical forum, and I felt a lot unfamiliar with my powershell philosophy. I carefully studied this script and recorded it on my blog.
How to install DOTNET framework 4.0 for many computers on the network at the same time.
1 $ hosts = Get-content-path "C: \ hosts.txt"
2 [scriptblock] $ script = {
3 # $ erroractionpreference = "stop"
4 $ machinename = GC env: computername
5 c: \ windows \ system32 \ net.exe use "\ remotemachine \ sharedfolder \ dotnetframework 4.0" password/User: domain \ Username
6 if (! (Test-path "C: \ Temp "))
7 {
8 New-item-path "C: \ Temp"-itemtype directory
9}
10 copy-item-path "\ remotemachine \ sharedfolder \ dotnetframework 4.0 \ dotnetfx40_full_x86_x64.exe"-destination "C: \ Temp"-force-recurse
11 function launchprocessandwait ([String] $ filename, [String] $ commandlineargs)
12 {
13 # preferences
14 $ erroractionpreference = "stop"
15 try
16 {
17 write-host "Starting Process $ filename on machine $ ($ machinename )"
18 $ P = start-process-filepath $ filename-argumentlist $ commandlineargs-wait-passthru
19 write-host "the process $ filename exit code is $ ($ P. exitcode )"
20 return $ P. exitcode
21}
22 catch
23 {
24 write-host "error launching process $ FILENAME"
25 throw
26}
27}
28 launchprocessandwait "C: \ temp \ dotnetfx40_full_x86_x64.exe" "/I/Q"
29}
30 $ cred = Get-credential
31 $ sessions = $ hosts | New-pssession-credential $ cred
32 invoke-command-scriptblock $ script-session $ sessions
33 $ sessions | remove-pssession
Other solutions:
-Credssp is very important. otherwise, the installation will be blocked by the remote machine's Unc, And the credssp must be enabled for all remote machines. this works only from vista sp1 onwards since credssp is not available on XP SP3.
Code
1 $ cred = Get-credential
2 invoke-command-computername "server01"-scriptblock {start-process-filepath "\ staging \ share \ tags"-argumentslist "/Q/norestart"}-credssp-crdential $ CRED