首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用powershell卸载远程客户端上的软件

使用powershell卸载远程客户端上的软件
EN

Stack Overflow用户
提问于 2013-11-15 15:13:38
回答 1查看 4.6K关注 0票数 0

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

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

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

它大约有900个客户端,所以一个脚本会很有帮助。

此外,如果可以在脚本完成后获得哪些客户端卸载了软件,哪些客户端没有卸载软件的列表,那就更好了。

EN

回答 1

Stack Overflow用户

发布于 2013-11-15 18:33:55

像这样的问题很可能会引起“你尝试过什么”类型的回复……

我推荐使用Windows Installer Powershell Module Uninstall-MSIProduct

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

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

代码语言:javascript
运行
复制
[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)"
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19995482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档