-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-Package.ps1
More file actions
54 lines (44 loc) · 1.65 KB
/
Copy pathRemove-Package.ps1
File metadata and controls
54 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<#
.DESCRIPTION
Remove-Package wraps Uninstall-Package in an Invoke-Command scriptblock for quick package removal on multiple
computers.
.SYNOPSIS
Remove-Package uses Invoke-Command to remove a target package from one or more computers, includes the -Confirm
option. Requires Nuget and PowerShell Remoting.
.PARAMETER ComputerName
Specifies which computer or computers to remove a target package from.
.PARAMETER Package
Specifies which package to remove from your list of computers.
.EXAMPLE
Remove-Package -ComputerName COMPUTER01, COMPUTER2 -Package "Microsoft Access database engine 2010 (English)"
Removes Access database engine 2010 from COMPUTER01 and COMPUTER02.
.EXAMPLE
Remove-Package -ComputerName (Get-Content -Path C:\servers.txt) -Package "Remote Desktop Connection Manager 2.7"
Removes Remote Desktop Connection Manager 2.7 from servers listed in servers.txt.
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True,
HelpMessage = "Enter the computers you would like to remove a target package from")]
[String[]]
[Alias("CN")]
$ComputerName,
[Parameter(Mandatory = $True, HelpMessage = "Which package would you like to remove?")]
[String]
$Package
)
Write-Verbose "Connecting to $ComputerName"
Write-Verbose "Checking $ComputerName for $Package"
$Test = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
Get-Package -Name $using:Package
}
Write-Verbose "Attempting to Uninstall $Package"
If ($Test -eq "True") {
Invoke-Command -ComputerName $ComputerName {
Uninstall-Package -Name $using:Package -Confirm
}
}
Else {
Write-Output "$Package not detected"
}
Write-Verbose "Script finished"