PowerShell - Remove-CMContentDistribution
hi,
i try remove app, packages os etc. remote dps , using remove-cmcontentdistribution. using try , catch method, catch appending on testing if 1 of packages missing write package names in-line - example
package not @ site or had error removing: adobe flash player 22.0.0.209 test test1
i have tried -append text file , csv.
here script -
$distrbutionname = "servername.com"
{ try
{ remove-cmcontentdistribution -distributionpointname $distrbutionname -applicationname $packages -verbose -force
}
catch {
"package not @ site or had error removing: $packages" | out-file "c:\scratch\psout\removepackage.txt" -append
}
if format , design code more , better able see mistakes:
$packages = get-content c:\scratch\psin\packages.txt $splat = @{ distributionpointname = 'servername.com' erroraction = 'stop'
verbose = $true } foreach($pkg in $packages){ try { remove-cmcontentdistribution -applicationname $pkg @splat } catch { write-host "$_" "package not @ site or had error removing: $pkg" | out-file c:\scratch\psout\removepackage.txt -append } }
you try/cstch block missing closure. code formatting have made obvious.
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment