Skip to main content

Posts

Showing posts from January, 2014

[PowerShell + WMI Eventing ] AD Group Modified --> Run a PowerShell Script

I knew it would be a great learning opportunity when Francois-Xavier Cat Sir  agreed to take me in his team for the Winter Scripting Games this year. FX Sir posted about this great Script which will monitor your AD Group for any changes and then email you the changes if any. You can find the blog post here Now while reading the post I had a question...So I did comment on the post there: Well until recently I found out that it could be done very easily. So in today's blog post I will show how to trigger a PowerShell Script when a Group in AD is modified. I got the answer to above question while reading this great book on WMI by Ravi Sir suggested to me by Laerte Junior Sir .  You can find the book here If you haven't guessed it by now the answer to making it possible is --- Wait for it " WMI Eventing ". I read this very cool thing on a blog:                  "The M in W M I stands for Magic"  - Kim Oppalfens So without further de

Calling PS1 from VBS and gotchas with cmdletbindingattribute() - Part 2

This post is in continuation of my previous post  where things got interesting while trying to execute a PS1 from a VBScript which will start/stop the website. At the end of post there was this interesting case where we tried to stop a website which did not exist ...But we would always get a Return code of 0 ...or Success message. Now that is bad for a Production Script as it should fail if we didn't give the correct website name. So for this post my sample VBScript will remain almost same with only one modification.....on the website name (in Bold Red below): Set  objShell =  CreateObject ( "WScript.Shell" ) strCommand =  "powershell.exe -noprofile -file C:\temp\test2.ps1 -websitename  WebSiteDoesnotExist  -action stop -verbose" strError = objshell.run(strCommand, 1 , True ) If  strError  then                              WScript.Echo  "Failed with Exit Code"  & strError &  "." else     WScript.echo  "S

Calling PS1 from VBS and Web-Administration without the PowerShell Module - Part1

Calling PS1 from VBS Recently I got this strange request to call PowerShell Script from VBScript... Yeah!! I am serious. Well the scenario is that we have a main VBScript which calls other VBScripts to perform Application Deployments on  Servers. In this main VBScript we want to add the functionality to start/stop websites and webapppools as these need to be stopped while deploying the web apps on the server. So to add this functionality to our VBS we want to use PowerShell Scripts. Learning ( skip these for now will make more sense after reading the post) :   WebAdministration Module doesn't work on a PowerShell Instance spawned by the VB Script. Can't really use Advanced Cmdlet Binding Attributes (next post) This task seemed to be easy enough at first ... Sample VBScript 1 : Set  objShell =  CreateObject ( "WScript.Shell" ) strCommand =  "powershell.exe -noprofile -file C:\temp\tes2t.ps1 -websitename DexTestWebsite  -action stop " s

SCCM 2007 + PowerShell -- Final Post

This is the last post on the SCCM 2007 + Automation Series in this blog. I will share the Script with which I was able to achieve automation of the Query Based Deployments. Finally using this Script I can Add machine names to the Query Membership Rule in a Collection...thus freeing myself of the GUI clicks needed in ConfigMgr Console. So I have a test collection by the name "Deepak test 1" and what I have done is removed all the Query Rules from it to show how the Script works. So Initially the collection has no Query membership rules, as evident from below screenshot of the Collection Properties in the ConfigMgr07 console: And below is a count of no of members inside the collection...No members I will be using the SCCM-Commands PowerShell module for my Script , I did cover some parts of it in previous post So I will describe the logic quickly.....I have a Function named Add-MachineToSCCMQueryRule which is the Function which will add specified machine na

PowerShell Validation Attributes -- validates in assignment

Validation Attributes in PowerShell ...Eh! I use them like everyday when I script.......But I noticed this thing recently. So suppose I have a sample function below: Now as you see it's nothing fancy..so just run it PS C:\> Test-ValidateRange -Param1 8 Param1 = 8 The variable cannot be validated because the value 11 is not a valid value for the Param1 variable. At line:19 char:5 + $Param1 = 11 + ~~~~~~~~~~~~ + CategoryInfo : MetadataError: (:) [], ValidationMetadataException + FullyQualifiedErrorId : ValidateSetFailure Param1 = 8 PS C:\> It seems that the validation attribute not only just run at the time when you first call the function ..but once you have defined a validation attribute on a parameter then through the lifetime of that variable/parameter if you do assign a new value to it then the validation attribute run against it ..thus guaranteeing that it has the value you wanted. To better see it you can save the file