PowerShell Script to delete Collections older than X Days under Specific Folder

Nicolas PilonPowershell, SCCM1 Comment

Did you ever wanted to delete a bunch of collections older than x days under specific folder name? I recently needed to clean collections older than 7 days under specific folders. The reason was simple, I came across a situation where the company own a custom package deployment solution and it create a collection each time a deployment is made. Since they are all limited collections, you can imagine the load it can create for the collection evaluator. The best solution would be to delete the collection as soon the deployment is succeeded, some internal politics prevents us to do that. Instead of doing it one by one, I decided to create an automate PowerShell script that run each week. The PowerShell script create a small report in a text file including the list of collections ID deleted. The file will be sent by email as an attachment and will be … Read More

Start-cmpackagedeployment error – Impossible to create a Required Package Deployment using CMDLET

Benoit LecoursPowershell, SCCM12 Comments

**Edit 2014/10/31 : I’m still struggling to make this cmdlet work with a Required schedule even if Microsoft says it’s fixed. If you have been able to make it work, leave a comment in this post. Start-cmpackagedeployment error ** **Edit 2014/06/27 : This issue is supposedly fix with R2 CU2 ** The Start-CMPackageDeployment cmdlet is failing with the following error when creating a “Required” deployment with a schedule. This CMDLet starts the deployment of a software package to a Configuration Manager collection. Run SCCM cmdlets and scripts by using the SCCM console or by using a Windows PowerShell session. When you run SCCM cmdlets by using the SCCM console, your session runs in the context of the site. Example : Start-CMPackageDeployment -CollectionName “$Name” -PackageId $PkgId -StandardProgramName “Install”  -DeployPurpose Available -DeploymentAvailableDay “2014/06/13” -DeploymentAvailableTime “12:12” -DeploymentStartDay “2014/06/19” -DeploymentStartTime “2:45”-RerunBehavior RerunIfFailedPreviousAttempt -SoftwareInstallation $True -SystemRestart $False Error : Start-CMPackageDeployment : Parameter set cannot be resolved using the specified named … Read More

SCCM Task Sequence Page File Location change using PowerShell

Benoit LecoursPowershell, SCCM7 Comments

SmsSwDistCacheDirDelete in ccmsetup.log 03

You can script the placement of the Windows page file in your SCCM Task Sequence. Sure you could use the good old wmic pagefileset but we’re in 2014, Powershell is your new friend! SCCM Task Sequence Page File Location Script My clients needed a script that : Disable page file on OS drive Move it to D: Set the page file based on the allocated memory installed (x1.5) I used a Powershell module found here. My Script then uses a function of this modules to fits my needs. Save this script in a .ps1 file. #Reads the physical memory and multiplies it by 1.5 $PageFileSizeMB = [Math]::Truncate(((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory) / 1MB) * 1.5 #Sets a Page File of 1.5 * Installed Physical Memory on D: drive Set-OSCVirtualMemory -InitialSize $PageFileSizeMB -MaximumSize $PageFileSizeMB -DriveLetter “D:” #Disable page file on C: drive Set-OSCVirtualMemory -None -DriveLetter “C:” #–end— **You can change the values for the drives … Read More

SCCM Change Drive Letter using Powershell in OSD Task Sequence

Benoit LecoursPowershell, SCCM5 Comments

SmsSwDistCacheDirDelete in ccmsetup.log 03

By default, Windows will assign the next available letter to your CD/DVD ROM drive. For servers and even workstation, it could be useful to change it to a standard value. This post will describe how SCCM Change Drive Letter in an OSD task sequence. In computer data storage, drive letter assignment is the process of assigning alphabetical identifiers to volumes. As an SCCM admin, you should always find ways to optimize your work and stop doing repetitive tasks. Add a Run Command Line step at the end of your task sequence that runs a PowerShell command. The latest SCCM 1902 Version can now directly enter Windows PowerShell code in the Run PowerShell Script step. This change lets you run PowerShell commands during a task sequence without first creating and distributing a package with the script. %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command “(gwmi Win32_cdromdrive).drive | %{$a = mountvol $_ /l;mountvol $_ /d;$a = $a.Trim();mountvol z: $a}” You change the … Read More

SCCM 2012 Management Point Error 1603

Benoit LecoursPowershell, SCCM2 Comments

We have recently experienced a SCCM 2012 management point error 1603. Scenario : Installing a new MP gives an error 1603 SCCM 2012 R2 Windows 2012 R2 The first thing to check is the MPSetup.log, you can see the error 1603 but you have not much information about what’s the problem really is. You have to dig deeper in the MPMsiLog.LastError to see the root cause.                     As you can see the error is cause by a previous version of the client being installed on the server. My environment had SCCM 2007 configured with the client push so my 2007 client was installed.                                         I’ve removed the client using ccmsetup /uninstall and remove the MP role. Still the same error then re-adding … Read More

Add SCCM Distribution Point Powershell

Benoit LecoursPowershell, SCCMLeave a Comment

Working in a large environment with lots of DPs, I don’t like to add my distribution point manually. Since SCCM 2012 SP1 CU1, there’s a new Add-CMDistributionPoint CMDLET to do the dirty work. This blog post will describe how to add SCCM Distribution Point Powershell. Choose a site system server as a distribution point before content can be made available to client computers. Assign a distribution point to at least one boundary group before on-premises client computers can use that distribution point as a content source location. Add the distribution point role to a new site system server, or add it to an existing site system server. SCCM Distribution Point Powershell First, you need to add your site system in SCCM using this CMDLET (replace with your server name and site code) New-CMSiteSystemServer -Servername “xxxx.yourdomain.com” -Sitecode PS1 Once run, you’ll see your new site system added to the SCCM console. After, you need to … Read More

Remove Computer from Collection after OSD

Benoit LecoursPowershell, SCCM1 Comment

This post is a step-by-step guide on how to remove computer from collection after OSD. If you’re using specific collections for your OSD deployments you certainly knows that the collections are not emptied automatically. After a couple of weeks, you’ll end up with a collection full of systems. The bad news is that there’s nothing built-in the product, the good new is that our friend PowerShell can do this dirty job. To run the script : The imported module needs to be trusted The script must run in x86 mode The computer account must have proper permission (SCCM and DCOM) Permission You need to add your primary site computer account as a “Full Administrator” in SCCM You need to add the “System” account “Remote Access” right in DCOM permission Launch “dcomcnfg.exe” Navigate to Component Services / Computer / My Computers (Right-Click) / Properties Edit Default in the Access Permission section … Read More

Add Server Requirement using Powershell

Benoit LecoursPowershell, SCCM1 Comment

SmsSwDistCacheDirDelete in ccmsetup.log 03

Before an installation of SCCM, you need to enable a couple of requirements in sccm 2012 server roles and features. You can add these using the server manager snap-in but since you are a good admin, you know that you can use Powershell ! Here’s the commands I use in the script to enable the required roles before my SCCM installations : Get-Module servermanager Install-WindowsFeature Web-Windows-Auth Install-WindowsFeature Web-ISAPI-Ext Install-WindowsFeature Web-Metabase Install-WindowsFeature Web-WMI Install-WindowsFeature BITS Install-WindowsFeature RDC Install-WindowsFeature NET-Framework-Features Install-WindowsFeature Web-Asp-Net Install-WindowsFeature Web-Asp-Net45 Install-WindowsFeature NET-HTTP-Activation Install-WindowsFeature NET-Non-HTTP-Activ Run it in a PowerShell prompt and get a coffee while the magic happens, you earn it ! You can have more details here. sccm 2012 server roles and features