Skip to main content

Posts

Showing posts with the label WMI

PowerShell + SCCM : WMI Scripting

Why should I use WMI, when there is a PowerShell module available for Configuration Manager (CM Module) already? Well the cmdlets behind the scene interact with the WMI layer and if you know which WMI classes the corresponding cmdlet work with , it can be of help in future by : Switching to native WMI calls when the CM cmdlets fail for some reason (probably bug in the CM Module). Making your scripts more efficient by optimizing the WMI (WQL query) calls, the cmdlet will query all the properties for an Object (select *) you can select only ones you need.  Lastly no dependency on the CM Module, you can run these automation scripts from a machine not having the CM console installed (needed for CM module). Moreover ConfigMgr uses WMI extensively, you already have this knowledge leveraging it with PowerShell shouldn't surprise you. This post assumes you have been working with CM cmdlets (you already are versed with PowerShell), know where the WMI namespace for ConfigMgr resides ...

PowerShell + SCCM 2012 : Create Packages & Programs

It has been a while, since I chartered the waters of WMI and Configuration Manager, so pardon any silly mistakes made. One of my friend from PSBUG asked me few questions revolving around creating packages & programs in ConfigMgr using PowerShell. Every ConfigMgr admin knows that new Application model has been introduced in ConfigMgr 12 but the Packages are here to stay for a while. Packages and Programs are ideal for deploying Scripts (one time or reoccurring ones) and better suited for deploying apps during OSD (heard this one). ConfigMgr ideally has 3 ways of working with it and below is the pic which says it all : The post is broken up in 3 parts (based on how you use ConfigMgr): GUI Way - Doing this to show background on how we do it manually. Cmdlet Way - using the CM cmdlets to create the package and program WMI Way - exploring WMI to do the same.

PowerShell + SCCM : Get Resource Collection Membership

Recently at our PowerShell Bangalore User group, we had fun participating in a one day PowerShell + ConfigMgr Hackathon event. Where we had a bunch of ConfigMgr admins worked on using Azure to deploy a full fledged ConfigMgr Lab, also we had fun interacting with each other. Below pic was the theme for the event, says it all ;) My friend Harjit  suggested few ideas for the Hackathon. Below is one of the ideas: " Script that can tell me which collections a particular system or several Systems belong to " The Final Script is available @Technet for Download      

PowerShell + SCCM - POSH Deploy v1

I wrote an article for the coveted PowerShell Magazine on how to automate query based deployments in ConfigMgr using PowerShell. http://www.powershellmagazine.com/2014/07/22/automating-deployments-in-configuration-manager-with-powershell/ If you go through that article you will get a background of this post. So continuing to that, I present " POSH Deploy v1 " which can be used to automate Query Based deployments with Configuration Manager (tested it on CM 2012 only). I had a similar tool built in my previous project for SCCM 2007 but that one had a lot of hard coded values, tried to remove those. The tool earlier used Winforms and this time I kicked myself to try out WPF with PowerShell . Thanks to StackOverflow and blog posts shared around these topics by awesome community people :)

PowerShell + WMI - Static & Instance Methods

One has to get their feet wet with WMI when it comes to managing ConfigMgr with PowerShell. How ConfigMgr uses WMI ?  Not only ConfigMgr but for other products if you leverage WMI with PowerShell then understanding what are Static & Instance methods is important. But there are lot of places where People stumble ( I did too ). Below is a question asked in Hyderabad PowerShell User Group (PSHUG) showing one of the common point of confusion. If you are a ConfigMgr Admin then you already know that in SCCM client we have a lot many Client actions that can be triggered remotely. Below are the available SCCM Client actions (In CM 2012) : Going back to the question, below code will work,which is triggering "Software Inventory" on a remote $machine: 001 002 $Client1   =  $( [WmiClass] "\\$Machine\ROOT\ccm:SMS_Client" ) $Client1 . TriggerSchedule( "{00000000-0000-0000-0000-000000000021}" ) One can get more info o...

PowerShell + SCCM 2012 : Create Dependency Rules

Following on my last post on creating supersedence rules in ConfigMgr Applications with PowerShell, this post is all about creating dependency rules. The approach is very similar to the last one and Adam Meltzer had already posted the sample C# version of the code here  . Have to admit I tried to re-use the code from the last time and in the Process screwed one of the Applications (by putting up wrong serialized XML on the WMI Instance of the App). There can be multiple dependencies in ConfigMgr (attached with a OR or AND operator), but for the sake of simplicity we will look at a very simple scenario  : Scenario: For Application 1 ( Notepad++ in this case) we will add an Application 2 (e.g .NET 4 ) as the dependency. I know that hardly is a dependency but I am a bit lazy to create other applications at the moment...though I can do that with #PowerShell too..but am too lazy for that too :P  At the end of the Code we will get this relationship: Code...

PowerShell + SCCM 2012 Tip : Get OS Inventory

Another post inspired by the daily job as a ConfigMgr Admin. Usually while deploying applications as a best practice we check few details about the machine like the Operating System it's running on to ensure that we deploy the correct package targeted to the correct OS. In past there have been cases where a package targeting XP was send to a Windows 7 machine or vice-versa. So how do I check OS information : If Machine is online ;Use PowerShell or any other tool to query WMI to get the info. If Machine is offline ;Head over to SCCM Reports to see the info We can use PowerShell to do perform the second part as well because ConfigMgr SMS namespace  provider stores this information in the class named SMS_G_System_Operating_System . Note - The data in the class SMS_G_System_OPERATING_SYSTEM is stored as a result of the Hardware Inventory of the Win32_OperatingSystem class on a remote machine. So if the H/W Inventory has not run then this data is not ava...

PowerShell + SCCM Tip: Get MachineName for a User

While doing Application deployments , we have cases where the User forgets to specify the Machine Name to which a software needs to be deployed to. We use Query-Based Deployment rules in ConfigMgr where we add the machine names to a Collection named after the Application..have already automated this process ;) But if the machine name is not specified then we either: Get the Machine name from SCCM Reports if available. Drop an email to the Requester for the same For getting the machine name for a User in ConfigMgr 07 we use the Reports obviously :D The report is located under "Users" node in ConfigMgr Reports page. But actually this can be retrieved using WMI/CIM too. The Class which has this info is SMS_R_System under namespace Root/SMS/site_<SiteCode> and let's take a look at it. Note: Before going further I have already set the ComputerName parameter and namespace parameter in the $PSDefaultParameters. Below is how you do it in...

PowerShell + SCCM 2012 R2: Get the Device/ User Info WMI Way

This is in continuation of my last post on Using PowerShell to get client information   In this post will be exploring on the ways to do the same thing using WMI/CIM, Why ? With WQL syntax we can ask for only the properties we need rather than getting everything back. The post will cover 3 topics: Query individual Device in CM using WMI/CIM Query Members of a Device Collection using WMI/CIM Query Users in a User Collection using WMI/CIM To get the number of properties got back from a call to Get-CMDevice use Get-Member and Measure-Object like below: Most of the properties returned back may be empty depending on how you are using ConfigMgr e.g if you use endpoint protection than those attributes in the class will be populated else will be empty. Now if you see the output of Get-CMDevice is actually is a result of the SMS_CombinedDeviceResources Let me tell you a little secret :-$ ...if you are looking forward to explore WMI part of ConfigMgr and have a...

Remotely Set State and StartMode of a Service using PowerShell

Well as the name suggests this is a very simple and straightforward post. Most of the PowerShell Geeks out there already know that we can do it in various ways: Using Set-Service Using PSRemoting Using WMI (Win32_Service) In our environment at office we don't have PSRemoting yet enabled, but it's okey we can come around that. In addition would like it to be PowerShell v2 compatible you never know who asks you for this Script running on v2. We can use Set-Service which has - ComputerName parameter, in case you haven't checked. But it fails to start/ stop a remote service if there are dependent services. C:\> gsv -Name bits -ComputerName DexterClient1 Status Name DisplayName ------ ---- ----------- Running bits Background Intelligent Transfer Ser... C:\> Set-Service -Name BITS -Status Stopped -ComputerName DexterClient1 -Verbose VERBOSE: Performing the operation "Set-Service" on target "Bac...