-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add remove-packages and bump version * remove on branch main * update docs
- Loading branch information
Showing
4 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ on: | |
push: | ||
tags: | ||
- '*' | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
--- | ||
external help file: OpenDriverTool-help.xml | ||
Module Name: OpenDriverTool | ||
online version: | ||
schema: 2.0.0 | ||
--- | ||
|
||
# Remove-Packages | ||
|
||
## SYNOPSIS | ||
Removes old driver packages from your SCCM site. | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Remove-Packages [-Make] <String> [-PackageType] <String> [-SiteCode] <String> [-SiteServerFQDN] <String> | ||
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
{{ Fill in the Description }} | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
```powershell | ||
PS C:\> Remove-Packages -Make Dell -PackageType Driver -SiteCode CAS -SiteServerFQDN abc.contoso.com | ||
``` | ||
|
||
Will remove all old driver packages from the specified sccm site. It leaves only the latest driver package. | ||
|
||
## PARAMETERS | ||
|
||
### -Confirm | ||
Prompts you for confirmation before running the cmdlet. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: cf | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Make | ||
Manufacturer of the computer. | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
Accepted values: Dell, Microsoft | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -PackageType | ||
Type of package to clean up and remove. | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
Accepted values: Drivers, BIOS Update | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -SiteCode | ||
Specify the sitecode of the confimgr site to connect to. | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 2 | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -SiteServerFQDN | ||
Specify the site server fqdn to connect to. | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 3 | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -WhatIf | ||
Shows what would happen if the cmdlet runs. | ||
The cmdlet is not run. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: wi | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -ProgressAction | ||
{{ Fill ProgressAction Description }} | ||
```yaml | ||
Type: ActionPreference | ||
Parameter Sets: (All) | ||
Aliases: proga | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
## INPUTS | ||
### None | ||
## OUTPUTS | ||
### System.Object | ||
## NOTES | ||
## RELATED LINKS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
function Remove-Packages { | ||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] | ||
param ( | ||
[Parameter(Mandatory)] | ||
[ValidateSet('Dell', 'Microsoft')] | ||
[string] | ||
$Make, | ||
|
||
[Parameter(Mandatory)] | ||
[ValidateSet('Drivers', 'BIOS Update')] | ||
[string] | ||
$PackageType, | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$SiteServerFQDN | ||
) | ||
|
||
$SearchString = '{0} - {1} *' -f $PackageType, $Make | ||
|
||
Write-Debug -Message $SearchString | ||
|
||
Connect-SCCM -SiteCode $SiteCode -SiteServerFQDN $SiteServerFQDN | ||
|
||
Push-Location ('{0}:' -f $SiteCode) | ||
|
||
$QueryResult = Get-CMPackage -Name $SearchString -Fast | ||
|
||
$CMPackages = $QueryResult | Group-Object Name | Where-Object Count -gt 1 | ||
|
||
foreach ($Group in $CMPackages) { | ||
|
||
$PkgsToDelete = $Group.Group | Sort-Object -Property SourceDate | Select-Object -First ($Group.Count - 1) | ||
|
||
foreach ($Package in $PkgsToDelete) { | ||
if ($PSCmdlet.ShouldProcess("$($Package.Name) Version: $($Package.Version)", "Remove Package")) { | ||
|
||
Remove-CMPackage -InputObject $Package -Force | ||
|
||
Pop-Location | ||
|
||
if (Test-Path $Package.PkgSourcePath) { | ||
Remove-Item -Path $Package.PkgSourcePath -Recurse -Force | ||
} | ||
|
||
Push-Location ('{0}:' -f $SiteCode) | ||
} | ||
} | ||
} | ||
|
||
Pop-Location | ||
} |