【问题标题】:Uninstalling software on a remote client using powershell使用 powershell 在远程客户端上卸载软件
【发布时间】:2013-11-28 12:22:46
【问题描述】:

我正在寻找一个脚本,它可以帮助我在我的网络中的多个客户端上卸载某个软件。

现在我正在浏览一个列表,远程访问客户端,使用我的管理员帐户登录并卸载软件,然后再注销并重复该过程。所有这些都是手动完成的,所以我希望你能帮助我编写一个 powershell 脚本来为我做这些事情。

可能出现的一些问题: 我无法远程登录,因为我无法与客户端建立连接。 另一个用户可能已经在客户端上登录。 被卸载的软件其实已经在我不知情的情况下卸载了。

大约有 900 个客户,所以脚本真的会有所帮助。

另外,如果有可能在脚本完成后,获得一个列表,其中列出了哪些客户端卸载了软件,哪些客户端没有卸载。

【问题讨论】:

    标签: powershell uninstallation


    【解决方案1】:

    这样写的问题很可能会引发“你尝试过什么”类型的回答...

    我建议使用 Windows Installer Powershell 模块 Uninstall-MSIProduct

    我在这篇文章中描述了如何远程使用这个模块:remote PCs using get-msiproductinfo,这个例子使用Get-MSIProductInfo,但可以很容易地更新为使用Uninstall-MSIProduct

    我已经快速将其更改为使用 Uninstall-MSIProduct,但尚未对其进行测试。

    [cmdletbinding()]
    param
    (
        [parameter(Mandatory=$true,ValueFromPipeLine=$true,ValueFromPipelineByPropertyName=$true)]
        [string]
        $computerName,
        [string]
        $productCode
    )
    
    begin
    {
        write-verbose "Starting: $($MyInvocation.MyCommand)"
    
        $scriptFolder   = Split-Path -Parent $MyInvocation.MyCommand.Path
        $moduleName     = "MSI"
        $modulePath     = Join-Path -Path $scriptFolder -ChildPath $moduleName  
    
        $remoteScript   = {
            param($targetPath,$productCode)
    
            Import-Module $targetPath
            uninstall-msiproduct -ProductCode $productCode
        }
    
        $delayedDelete  = {
            param($path)
            Remove-Item -Path $path -Force -Recurse
        }
    }
    process
    {
        $remotePath = "\\$computerName\c$\temp\$moduleName"
    
        write-verbose "Copying module to $remotePath"
        Copy-Item -Path $modulePath -Destination $remotePath -Recurse -Container -Force
    
        write-verbose "Getting installed products"
        Invoke-Command -ComputerName $computerName -ScriptBlock $remoteScript -ArgumentList "c:\temp\$moduleName", $productCode
    
        write-verbose "Starting job to delete $remotePath"
        Start-Job -ScriptBlock $delayedDelete -ArgumentList $remotePath | Out-Null
    }
    
    end
    {
        write-verbose "Complete: $($MyInvocation.MyCommand)"
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 2016-02-12
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 2011-03-25
      相关资源
      最近更新 更多