Skip to main content

Posts

Showing posts from 2013

SCCM 2007 + PowerShell - WMI is the key to automation Part 2

In Previous post I talked about how to explore the WMI namespace for ConfigMgr 07. In this post would like to point out on how to use the  SCCM-Commands PowerShell Module  , this Module leverages WMI with PowerShell. Many thanks to  Michael Niehaus,  Rikard Ronnkvist,  Stefan Ringler and  Ricardo Cheing  authors of this Module for sharing this. Download this module and extract it, it contains a single PowerShell Module file .this is a Script Module ( SCCM-Commands .psm1). Place this File under your Modules Directory in a folder named same as the module i.e. SCCM-Commands Now you should be able to see the Script module in you session like below: Now you have to import the module and then you can list all the Advanced functions shipped with this module using either of the below 2 ways:  1. Use Get-Command -Module SCCM-Commands  2. Or Use Get-SCCMCommands function within the module itself. Now the Functions in the Module are Advanced ones and don&

SCCM 2007 + PowerShell - WMI is the key to automation Part 1

Well in the quest of automating ConfigMgr 07.....WMI is the key. Now this post isn't a primer on how to use WMI with PowerShell. There are very good resources which you can hit like: Free Ebook by Ravi Sir (PowerShell MVP) - " WMI Query Language via PowerShell " (referred to me by  @LaerteSQLDBA  :) ) Book by Richard Siddaway (PowerShell MVP) - " PowerShell and WMI " There are other good resources like  HeyScriptingGuy's  blog where one can serach for WMI tag, there is whole bunch of information out there on leveraging WMI with PowerShell. If you haven't checked out this yet then you are missing something very cool to manage your Infrastructure. That being mentioned the journey to exploring WMI starts by connecting to the SCCM Site System which has the SMS provider installed. Open the ConfigMgr console > Connect to your Central Site/Primary Site > Site Management > Right -click site ...select Properties. The information where SMS

SCCM 2007 + PowerShell Automation - The Problem with Query Based Deployments

Few months back, I made a resolution of automating the deployment process used in our Project, Scenario So if a User needs applications in their machine , they raise a request for the same. After the approval process it comes to our team and we handle the deployment of these apps to the User machines using SCCM 2007 (or ConfigMgr). So this is how we do it ....we have the QueryRules for the Application collection in place we just go there and add the machine name there manually in the Query Rule for the Application Collection.  To go with the post I have a test collection in place by the name " Deepak Test 1 "...So first I will be showing how we do this manually and then later on how I did it using PowerShell. There something called "Click Count" which is a rough count of how many mouse clicks am using to do these actions in ConfigMgr MMC Console (rough estimate) Click Count = 1 Manual Way Step 1. Right  Click and open the properties for

PowerShell to Create a random Music Playlist in VLC

This is a trick which got famous at the PowerShell Bangalore User Group (PSBUG) session. Little trick to play a single random song provided VLC (or any other player) is set as default player for the .mp3 files:     Posh (0002) >    Get-ChildItem -Path 'F:\songs\movies neew' -Include *.mp3 -Recurse | Get-Random -Count 1 | Invoke-Item  But this won't create a playlist for you if you simply increased the count for Get-Random..try this     Posh (0003) >    Get-ChildItem -Path 'F:\songs\movies neew' -Include *.mp3 -Recurse | Get-Random -Count 2 | Invoke-Item Let's try creating a playlist this time ( have to set VLC as  the default player for .mp3 files , thus creating filetype associations for .mp3 files)  You need get all the possible list values for mp3 extension.I read this excellent article by David Moravec at  PowerShellMagazine  to list all possible verb values for a particular extension. After you go through the above mentio

using throw inside param() block

Recently I had to write  a very restrictive script which takes few arguments like a filename, computername etc. These parameters need to be compulsory otherwise the script should not run... Below is the first function I came up with(nothing fancy): function   Test-AdvancedFunction   {      [CmdletBinding()]         param (            [Parameter(Position   = 0, Mandatory   = $true   )]            [ValidateScript({Test-path $_})]            [   System.String ]               $FileName      )       $Name       ## Normal Script Code goes here      } In the above in the param() block a  mandatory  named argument is specified and has a  ValidateScript  attribute. Everything looks great but the function needs to be very restrictive and it should fail when the parameter is not supplied to the function. Right now because of making the parameter mandatory , I get a prompt to supply the value as below : But I wanted my   function to fail if the

Drop to PowerShell using Remotely Anywhere

This is just basics but something I came across recently ,   remotely anywhere  is a remote administration tool which our Enterprise uses. Most of the time User face some issues with installation of applications , so Remotely anywhere helps in assisting them using the remote desktop using a web interface Remotely anywhere also listens on port 22 the name of the service is "RemotelyAnywhere SSH Server". Sojust connect to a remote machine using putty and then you are droppped to a  cmd shell  and then start PowerShell from there. The best part is it doesn't prompt for the User confirmation :) The pre-requisite is that Remotely Anywhere be installed on the remote machine and listening on port 22. So open up a putty console and connect on port 22. After that you need to authenticate yourself, I am logging into a machine in Enterprise (running AD) so I used my domain credentials to log in and you do need to After that you are dropped to a command prompt,

Use PowerShell to Create New AD Users using a Template

To use and existing account as a template to create new users one would use the good old "Active Directory Users and Computers" , right? by right-clicking on the User to be used as template and selecting "Copy" which will prompt something like below: But this blog is  meant for doing things using PowerShell. To quickly get me started I was tempted to use "Active Directory Administrative Center" on Server 2012, so that I could see the PowerShell history for the my actions( Yeah! you can do that now !!) but there was no method to do that in AD Admin Center :O , See below   The User "Dexter POSH" is the member of the group "RemotePOSHAdmins" under the OU "POSHAdmins" in my domain. I want to add a new User here using the dexterposh user account as the template. At first I thought of simply getting the User information using Get-ADUser and piping it into New-ADUser cmdlet (because it accepts pipeline input of type &q