惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
J
Java Code Geeks
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
IT之家
IT之家
博客园_首页
B
Blog RSS Feed
Google DeepMind News
Google DeepMind News
B
Blog
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
博客园 - 聂微东
腾讯CDC
A
About on SuperTechFans

博客园 - 挖土.

学笛子 PowerShell: Try...Catch...Finally 实现方法 How to set the compuder to auto login 让 PowerShell 2.0 支持 DotNet FrameWork 4.0 PowerShell 调用.netFramework中的静态函数 PowerGUI Visual Studio is now in beta! PowerShell 中定义和使用泛型 PowerShell 如何引用DLL PowerShell中Add-Content 和 Out-File 的区别 给string加几个扩展方法 加快 c++ Builder 5编译速度 Windows 7 下的 SUBST 命令 How to configure the BDE for Windows Vista/7 - 挖土. Linker problems with Borland builder SQL 中的中位值计算 Windows 7的“上帝模式” XML 序列化和反序列化详例代码 给存储过程传递一个表 VSIdeTesthost installation issue - 挖土.
用 Powershell 安装Dotnet FrameWorrk 4.0
挖土. · 2010-12-08 · via 博客园 - 挖土.

在微软的技术论坛上看到这个脚本,感觉自己的PowerShell 理念,还有很多不熟悉,好好研究了一下这个脚本,记录在自己的Blog上。


怎样同时为网络中很多电脑安装Dotnet Framework 4.0。

 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

另外的解决方法: 

-CredSSP 非常重要. 否则安装会被远程机的 UNC 阻止而失败,需要为所有的远程机启用 CredSSP. This works only from Vista SP1 onwards since CredSSP is not available on XP SP3.

代码

1 $cred = Get-Credential
2 Invoke-Command -ComputerName "Server01" -ScriptBlock { Start-Process -FilePath "\\Staging\Share\dotNetFx40_Full_x86_x64.exe" -ArgumentsList "/q /norestart" } -CredSSP -Crdential $cred