Category Archives: PowerShell

SCCM Client Cache Configuration Improved Powershell Script

In the past I posted how to configure or clear the SCCM client cache using Powershell scripts, but that method required a separate script for each cache size you might want to set. This new script allows on-the-fly modification of the CCM Cache from a task sequence using a single SCCM package containing this new Powershell script.

To use this script, you will need to create a package in SCCM with the source contents containing this script. You do not need to create a program for the package. Make sure the package can be used by task sequences without being deployed. After distributing the package, just call it from a task sequence using a “Run Command Line” step referencing the package.

Assuming you save the script as “sccmCache.ps1”, any of these usage examples will work:

And here is the Powershell script:

Continue reading

Powershell Shortcut Generator Script

I created this script for use with SCCM to allow easy creation of shortcuts during deployment for applications that do not create their own shortcut, or for portable applications that are not actually installed. The powershell script can be called upon from the “Run Command Line” step of a task sequence, and the script should be added as a Package to SCCM so that it can be referenced from the Package option inside the Run Command Line step.

This script generates shortcuts in the Public Desktop and the Start Menu. If a drive letter is specified in the path, it will be used. If no drive letter is specified in the path, the $env:SystemDrive variable will be used to figure out the drive letter based on the OS drive. If a URL is specified in the path, it will be used instead of a local path.

Here are some usage examples:

Here is the full script:

Continue reading

How to Set Wakeup Time for Laptop Computers in SCCM

SCCM’s power configuration options allow setting a wakeup time for computers, but only for desktops. Currently SCCM has no option to enable wakeup for laptops. The idea behind this is that a laptop can be in a bag and so should not be woken up automatically, but it would still be nice to have an option to enable this if you know for sure that your laptops will not be inside a laptop bag during the wakeup time, such as laptops used in lab environments.

Setting a wakeup time for laptops can be accomplished with a PowerShell script and a Task Scheduler task. This can be deployed with SCCM as a package targeting your laptop collections.

The first part is to enable wake timers using Powershell. SCCM’s power configuration options for a device collection can enable wake timers but again only for desktops, with no option at all to allow wake timers for laptops. This script can work with or without having an SCCM power configuration set for the device. As the device switches between peak and non-peak hours and therefore applies different SCCM power configurations automatically, it will still keep wake timers turned on when configured with this script. Here is the script (this one is floating around the internet – I didn’t write it), and you can selectively enable or disable wake timers for DC (on battery) and AC power (plugged in) by changing the $AllowWakeTimersGUI value for SETDCVALUEINDEX and SETACVALUEINDEX:

Continue reading

How to Configure or Clear SCCM Client Cache

If you need to clear the SCCM client cache or increase the cache size on individual clients, there are a few different ways to do it. One of the methods usually posted on a lot of blogs and forums is actually the wrong way to do it, because it requires restarting the CCMEXEC process on the client in order to update the new cache settings, which makes the task sequence used to deploy the script fail since CCMEXEC, which was running the deployment, has been terminated.

Here I will show you the right way to clear the CCM cache that does not require restarting the CCMEXEC process. This PowerShell script can be deployed with SCCM as a package or as part of a task sequence. Sometimes this method is preferable to using Right Click Tools, especially if you want to only change cache settings during application deployment, such as part of a task sequence that installs multiple large applications. Sometimes it doesn’t make sense to keep 30GB of installers cached on the computer and it’s better to just manually flush the cache after the installation completes.

Here is the script to clear the ccmcache:

Continue reading

How to enable DHCP using PowerShell

Enabling DHCP using PowerShell is very easy and can be accomplished in three lines of code. Yet for some reason many other online guides show the long way around.

I previously posted about how to set static IP’s using PowerShell. This script to enable DHCP can be a complementary program inside an SCCM package to configure IP addresses. That way, you can have an SCCM program to deploy a static IP and then another program to reset it back to DHCP, and both of these programs can be inside one package.

Alternatively, this script can be used as an Uninstall method if setting static IP’s using an application in SCCM, with a modified version of my network adapter configuration detection method script as the application detection method.

Either way, here is the short and simple script, with a log file output designed to add on to the previously mentioned Static IP script’s logs if they exist:

Continue reading

Programmatically Setting Static IP’s in a Computer Lab

If your organization has computer labs which require static IP addresses, here is a very easy method to deploy static IP’s to each lab. Most labs will have some sort of numbering scheme as part of the computer name. We can take advantage of this in order to transform the computer number into an IP address.

In my example, the computer number is at the end of the computer name. I am going to use PowerShell to calculate the new IP address for each computer, apply the new network configuration, register the new settings, and output a log file. Here is the script:

Continue reading

How to Crawl Websites to Download Software Updates with PowerShell

I wrote this script to check for updates to some common software used in my organization. In order to do so, the script uses PowerShell to crawl the website of each piece of software so that it can get the software version number and download link. The script compares the version of the software it found online to the version it found in the local folder inside the script directory. If the version online is newer, it downloads the file and renames it to a nice format including the version number. The software (64-bit where available) crawled for download is:

  • 7-Zip
  • Google Chrome
  • Mozilla Firefox
  • Mozilla Firefox ESR
  • Adobe Flash Player ActiveX
  • Adobe Flash Player NPAPI Plugin
  • Java
  • VLC Media Player

I figured this script would be a good example to share because it uses a few different methods to find the information it needs on each publisher’s website. Some people can find these examples helpful to modify the code to crawl for something else. In the case of Adobe Flash Player for enterprise distribution, the website requires a login, so I just left the script to check the version and then open a browser window going to the login screen so that the user can manually download the MSI files. Since the Adobe enterprise distribution license says the download link cannot be shared, I have edited it out of the script, so you will need to replace it yourself if you want to use this function. Just search for all instances of “https://INSERT-ADOBE-DISTRIBUTION-LINK-HERE” and replace it with the URL you received from Adobe.

I split this script into functions, with a function to download the software and a separate function to crawl the website for each piece of software. Inside of each crawl function, I split the variables and crawl methods that need modification. This also means that you can remove the last part of the script after line 315 if you would rather use the script to manually call each function using the PowerShell console in order to check for just one piece of software.

Again, this script is very application-specific, so unless you need to check for updates and download this specific set of software, you will need to modify the script for whatever software you need. Use it as a very broad example of crawling the web with PowerShell. There are many different ways to do this, and I’m sure some might be better, but this way works exactly as I need it to for my specific use case. And of course if a website for a particular piece of software changes, the crawl function for that software will break, but there’s no way around that with web crawling.

Here is the required directory structure for this specific set of software:

And here is the full PowerShell script:

Continue reading