PowerShell Splatting – Nice way to simplify your scripts

Currently I´m building PowerShell WMI Explorer and because of this tool supports alternate credentials, then I thought how can I simplify my Get-WmiObject queries and the solution is Splatting :) PowerShell splatting allows you to create Function or CMDLET parameters dynamically. Below example shows how you can build dynamically Get-WmiObject parameters. You can use this script to query WMI information from the local machine or from the remote computer and if necessary you can also add alternate credentials. [crayon-5a12c34099786362416647/]

By | 2013-06-08T10:58:54+00:00 June 8th, 2013|Powershell, Scripting & Development|0 Comments

PowerShell: Disable Automatic Loading of Modules in PowerShell 3.0

  One of the new features in PowerShell 3.0 is the Auto Loading of Modules. This feature is great for discovering commands, but can be really annoing when trying to test if your script works as it is supposed to. Luckily we can change the settings using an automatic variable. $PSModuleAutoloadingPreference Here is the info from the help: $PSModuleAutoloadingPreference------------------------------      Enables and disables automatic importing of modules in the session.       "All" is the default. Regardless of the value of this variable, you      can use the Import-Module cmdlet to import a module.      Valid values are:        All    Modules are imported automatically on [...]

Take control of your ConfigMgr Collections part 1

If you are managing a large ConfigMgr environment, then it is important to know when your collections updating their memberships and if your collections are updating exactly the same time, then it may hit your SQL very badly. This script reads all the collections and you can specify which output you want – CSV or HTML. You can download the script from here

System Center 2012 Configuration Manager SP1 Cumulative Update 1 PowerShell Parameter Sets Excel Sheet

I just updated the SP1 RTM version of Configuration Manager 2012 SP1 RTM PowerShell Parameter Sets Excel sheet and with SP1 CU1 we have 511 CMDLETS and 1675 parametersets :)   You can download the Excel Sheet from here Happy Scripting Kaido    

PowerShell – How to do WMIClass CreateInstance but WITH credentials

Today I was building a script to create system resources in SCCM 2012 and part of the task was to add these resources to a set of collections. The script will use from the SCCM server when finally implemented but for now I was using my laptop for editing and debugging. When I came to the point where I had to create the actual membership rules for the collections I ran into a hurdle that puzzled me. The WMI object I had to create was the SMS_CollectionRuleDirect, which often is done using this simple PowerShell snippet: $ruleClass = [WMICLASS]"\\$($server)\root\sms\site_$($sitecode):SMS_CollectionRuleDirect".CreateInstance() And [...]

PowerShell to the rescue – Clean up direct collection memberships

We where talking to a customer about how to avoid waiting for Active Directory group synchronization to occur and place a device in the correct collections faster than “until the next synchronization”. The main problem with this setup was caused by the fact that they used a group-in-group membership to identify collection memberships and apparently SCCM 2012 don’t include indirect changes to group membership as delta changes (I have not tested this in details yet). So we came up with the idea to just create a direct membership to place the device in the collections instantly to make sure that [...]

By | 2013-03-12T12:31:15+00:00 March 12th, 2013|Configuration Manager (SCCM), Powershell|3 Comments

How can I determine what Antimalware Policy is applied to my SCEP 2012 SP1 client

Niall Brady posted a blog post a few days ago How can I determine what Antimalware Policy is applied to my SCEP 2012 SP1 client. Niall showed how to check Antimalware Policy via registry or via Configuration Manager Console. Actually there is one method more - Antimalware policy is also stored in WMI class . You can use query below to identify the Antimalware policy from WMI. $EmptyPolicy= @() $EPPolicy = Get-wmiObject -namespace "Root\ccm\Policy\Machine\ActualConfig" -query "Select Name from CCM_AntiMalwarePolicyClientConfig" | ForEach-Object {$EmptyPolicy+=$_.Name} $EmptyPolicy | Group-Object | Select-Object -Property Name -Unique   Script Output  

By | 2013-02-22T18:53:09+00:00 February 22nd, 2013|Configuration Manager (SCCM), Powershell|1 Comment

CSV REPORT: Get ConfigMgr Collection Excluded or Included Collection Rules

Currently there should be no builtin report that will show you Excluded or Included collections and because of that I did two simple PowerShell scripts that queries Included or Excluded collections. Both of these scripts creates a CSV file. You can run this script on your Primary, CAS or Central site like this: Get-CMCollectionExcludedCollectionRules.ps1 -SiteCode PS1 -SiteServer Localhost -OutPut c:\Temp\ExcludedCollectionReports.csv Get-CMCollectionIncludedCollectionRules -SiteCode PS1 -SiteServer Localhost -OutPut c:\Temp\IncludedCollectionReports.csv Get-CMCollectionIncludedCollectionRules.ps1 Get-CMCollectionExcludedCollectionRules.ps1 Example Output  

By | 2013-01-31T14:47:18+00:00 January 31st, 2013|Configuration Manager (SCCM), Powershell|1 Comment

Quick and Dirty Management Point check

If you have a big Configuration Manager environment and you don´t have a monitoring solution like SCOM or NAGIOS, then PowerShell can help you too.  This script queries all Management Points from SMS_SystemResourceList WMI class and it will check MPCERT and MPLIST website status. If you want to use this script then run it on your Central, CAS or Primary Site Server like this: Get-CMSMPStatus.ps1 -SiteCode PS1 -SiteServer Localhost -OutPut c:\Temp\MPStatus.csv. This will create a CSV Report (example below) This script should work with PSH v2 and v3. You can download the code example from here

By | 2013-01-29T14:20:44+00:00 January 29th, 2013|Configuration Manager (SCCM), Powershell|1 Comment

Powershell to change Resolution State in Operations Manager 2012

A powershell sample used at a customer for semi-automatically changing the Resolution States: [crayon-5a12c3409b2af650096050/] [crayon-5a12c3409b2b6037125002/] [crayon-5a12c3409b2ba050236754/] [crayon-5a12c3409b2bd209409705/] [crayon-5a12c3409b2bf582464567/] [crayon-5a12c3409b2c2247040580/] [crayon-5a12c3409b2c5482709923/] [crayon-5a12c3409b2c8596910521/] [crayon-5a12c3409b2ca503645367/] [crayon-5a12c3409b2cd990564249/] [crayon-5a12c3409b2d0160395180/] [crayon-5a12c3409b2d2850782464/] [crayon-5a12c3409b2d5484982981/] [crayon-5a12c3409b2d8234750307/] [crayon-5a12c3409b2da100298412/] [crayon-5a12c3409b2dd790305643/] [crayon-5a12c3409b2df897582493/] [crayon-5a12c3409b2e2674614892/] [crayon-5a12c3409b2e5234485661/] [crayon-5a12c3409b2e7614319076/] [crayon-5a12c3409b2ea071113050/] [crayon-5a12c3409b2ec226541096/] [crayon-5a12c3409b2ef106308200/] [crayon-5a12c3409b2f2329362522/] [crayon-5a12c3409b2f4580881343/] [crayon-5a12c3409b2f7080974575/] [crayon-5a12c3409b2f9942018920/] [crayon-5a12c3409b2fc860606777/] [crayon-5a12c3409b2ff510604811/] [crayon-5a12c3409b301982491304/] [crayon-5a12c3409b304390035403/] [crayon-5a12c3409b307026794458/] [crayon-5a12c3409b309631775383/] And have a great Day Kåre

By | 2017-08-22T13:05:40+00:00 November 13th, 2012|Automation, Operations Manager (SCOM), Powershell|3 Comments

Eject CD script, quarantined by FEP! PowerShell to the rescue!

I guess everyone knows that you can’t enable BitLocker on a machine from a Task Sequence if there is a CD in the CD drive… The workaround is quit simple, just run a script to eject the cd drive before running the “enable BitLocker” step. Well the other day this script, a vbs, I use, was removed by Forefront.. I guess the heuristic scan evaluated the content of the script to be unsafe, and quarantined it.. This is obviously not good, as it’s needed by the task sequence… So I thought, maybe there is a way to eject the CD [...]

By | 2012-03-22T12:25:53+00:00 March 22nd, 2012|General info, OS Deployment, Powershell, Security|3 Comments

Small useful scripts–Changing Driver Package source (PS1)

I have this customer who had to move all driver packages from from one server a another. This of cause meant all the Data Source references had to be change as well. Once al the packages were moved to the new server I ran the following  two scripts to change the source. All you need to change is the $Site to your site code, or add it is a parameter when you run the script. You will obviously also have to type in the old and new path. Syntax: Script.ps1 –Site XXX If you want to only run against one [...]

WMI/ConfigMgr Scripting: CreateEmbeddedObjectInstance (.NET) or SpawnInstance (VBScript) in PowerShell

  During the development of the script I posted yesterday, I noticed that a lot of people had problem discovering how to create WMI objects in PowerShell. I found different suggestions, but they all had problems. When I have to create WMI object instances I use this this method, which I used in my old script about sharing folders here is an example: [crayon-5a12c3409dcc4559125461/] using configuration manager development we have to create a lot of wmi objects. Take a look at this SDK Sample in the VBScript example we have this line: [crayon-5a12c3409dccc189737425/]   and in the C# example it [...]

System Center Orchestrator 2012 Beta: Using Run .Net Script Activity – PowerShell: Inputting and Returning Data

This article describes how to use the Run .Net Activity to run PowerShell Scripts. I have created an example runbook which does the following: Start once every minute. Read a text file containing a list of sites/servers. Parse the list to PowerShell script. PowerShell script tried to ping each address and get the response time. PowerShell script output formatted HTML, ready to put inside a HTML Table, containing the addresses and response time. Runbook writes a web site based on a HTML template. The result is a website, in my case it looks like this: NB! some websites/server [...]