Freeing up some space on our DP’s

We were running low on disk space on our DP’s and I noticed we had a lot of packages with the “Copy the content in this package to a package share on distribution points” check box checked on packages that didn’t need it. This, as you probably know, causes the package to have 2 copies on each DP. The only time we needed this checked was on a package that was either referenced by a task sequence or had a deployment that ran from DP. So, I wrote a script that will fix this, based on the switches you use.

The basic breakdown  of the script is this:

Here we define our parameters for the script and, in some cases, set the default values. We also import in the ConfigManager PSModule.

Next, we define the New-LogEntry function. This will right out the message to a log using a format that can be read with CMTrace.exe

We finish up the initialization here by first setting the Log and CSV file names. We figure out the Site code, and change the location to the site code (so the ConfigurationManager PowerShell Cmdlets will work). Last, but not least, we log our settings. Now, let’s get to work!

First thing we do is get a list of the task sequences and a list of deployments. This will be used later to verify if a package has a deployment where the “Run from DP” option is set and/or if the package is referenced by a task sequence. While we’re at it, we also get a list of the packages.

 

In this section, we start our foreach loop and log the package we are checking. We initialize some flags to indicate if the package is referenced by a Task Sequence or has a deployment with “Run from DP”. The $Entry variable will be a log entry later, so we start it with the Package ID. Then the next foreach loop, we look to see if the package is referenced by a task sequence, if it is, we set the TSSMatch to true and add to the $Entry variable. The next foreach loop, we look to see if the package has a deployment with “Run from DP” set, if it does, again, we set a variable, this time PKGMatch, to true and add to the $Entry variable. The last thing we do is note if the package has the CopyContent check box checked or not.

Now we’re ready to fix things. If either of the two conditions checked come back true, then we should have the check box checked. Now we check to see if the package has the check box checked or not. If it doesn’t, we log this. We then check to see if the switch was set to fix this and if the package is smaller than the MaxPackageSize, we will set the check box and redistribute. We note this so, if required, we can update the CSV file.

The last part is basically the opposite of the last step, checking to see if the check box is checked when it shouldn’t be and fixing it if asked and the package is larger than the MinPackageSize. The last part is logging that we’re done!

This script is available in it’s entirety in my Repository section, found at the top. I hope you can use this script and welcome any comments, suggestions, or improvements!