Use powershell to install DOTNET frameworrk 4.0

Source: Internet
Author: User
Tags dotnet

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

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.