• 用 Powershell 安装Dotnet FrameWorrk 4.0


    在微软的技术论坛上看到这个脚本,感觉自己的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
  • 相关阅读:
    11-8 Eureka Server整合SpringSecurity解决安全问题
    11-7 Eureka Server安全问题介绍
    11-6 CORS跨域资源共享解决
    11-5 JWT验证演示
    11-4 JWT验证开发演示
    11-3 JWT颁发流程讲解
    11-2 JWT介绍
    11-1 服务安全章节介绍
    10-15 Zuul知识点梳理
    10-14 Zuul与Meetingfilm整合
  • 原文地址:https://www.cnblogs.com/digjim/p/1899897.html
Copyright © 2020-2023  润新知