Batch Increment file names with PowerShell

Nowadays I’m writing a book related to Windows Server 2012 in Turkish. My publisher asked me to rename all jpeg file names to incremented file names as follows:

imagexx.jpg to IMAGE-1.JPG

imageyy.jpg to IMAGE-2.JPG

imagezz.jpg to IMAGE-3.JPG

It is pretty easy with powershell,

Dir *.jpg | ForEach-Object  -begin { $count=1 }  -process { rename-item $_ -NewName “IMAGE-.$count.jpg”; $count++ }

You can start with count number 1 or any number you want. I hope my second book will be realeted to PowerShell 🙂

PSRemote Parameter set cannot be resolved error

While using New-PSSession and Invoke-Command to execute cmdlets on remote machines you may receive following error message:

Invoke-Command : Parameter set cannot be resolved using the specified named parameters.

If you are using –authentication parameter twice, this causes above error message. Using authentication parameter within New-PsSession would be enough

$session =  New-PSSession -Credential $credential -ComputerName “XXX” -Authentication CredSSP

Invoke-Command -Session $session -Authentication CredSSP -ScriptBlock {SCRIPT BLOCK}

remove authentication from Invoke-Command line.

Again and again.. System Center MVP Award


I have just received an email from Microsoft that i have been awarded as MVP for 2013 in Cloud and Datacenter Management expertise section.

Some of you may know that i lost my ConfigMgr MVP title when i joined to Microsoft. But for a while i’m not a MSFT anymore and this is why i have been choosen as MVP again.

Thanks to MVP program and our MVP Lead.

Hypervisor Early Launch

One of the interesting architectural changes in Hyper-V 2012 Server is the boot order. In Windows Server 2008, first booted partition was the OS in parent partition. After booting partition it was launching Hypervisor using hvboot.sys.

hvboot.sys was performing following actions:

  • Detects whether a hypervisor is already loaded or not
  • Determines processor if it is Intel or AMD
  • Loads hypervisor image
  • Invokes hypervisor launch code
  • virtual processor is created

In Windows Server 2012 and Windows 8, now it does early launch of hypervisor before OS and applies microcode updates needed. Therefore OS in the parent partition is booted on a Virtul Processor.

This change also allows you to be able to manage more than 64VPs.

WS-Management / WinRM Standards

In 2005, Microsoft submitted WS-Management for DMTF standardization along with 12 other companies.  It simply provides a standard for building XML messages using web service standards. It can be used to manage PCs, devices, Web services and other manageble entities. The messages that are provided by WS-Management are the conventions of Simple Object Access Protocol aka SOAP.

SOAP is a protocol specification relies on XML for its message format. It allows for the use of different transport protocols and uses HTTP as a transport protocol.

As for WinRM, it is the implementation of WS-Management protocol by Microsoft. It provides a firewall-friendly, HTTP based way to manage hardware and operating systems across different vendors. Moreover Windows PowerShell remote feature works on WinRM technology. You can manage not only Windows systems but also non-windows systems such as Unix computers. Windows systems are managed over WMI and non-windows systems are managed over DCOM.

All data that is captured using WinRM are formatted in XML as follow:


As of January 30, 2013, WS-Management was adopted as an international ISO/IEC standard.

That is really really important since that means using WS-Management protocol to manage complex systems will be much more simplified. All new System Center components and Windows Server 2012 aka Cloud OS are using WS-Management and Win-RM.

That is exactly means that, if you decide to manage your cloud environment with System Center and Windows Server 2012, you will also have ISO/IEC standard while managing remote systems.

In addition to this, Microsoft has designed Open Managed Infrastructure (OMI) as an open source project. It helps you to implement a standards-based management service into any device from a free open source package using WS-Management ISO/IEC standard.

How to parse DCDIAG output with PowerShell

Finally added latest version to Technet Script Gallery. No need to send e-mail to me 🙂

All is started with the idea of creating an Active Directory Health Check script. I decided to combine couple of existing domain monitoring tools’ outputs and create one single, well designed HTML output.

At the end of the day i have following outputs:



Sorry for the pinky boxes, they are to hide customer DC names Smile

In this post i want to get into details of parsing dcdiag output with powershell. In my script, DCDIAG output  includes four columns as follows: Advertising, Replications, Services, Netlogon. It’s possible to add additional tests.

And for the passed tests rows will be green, for the failed tests rows will be red. One more thing, for the failed rows you can add hyperlinks as follow:


Let’s start:

As you know DCDIAG is a command line tool that analyzes the state of your domain controllers in your organization and reports for errors and warnings to assist while troubleshooting. It has couple of parameters to run across your domain controllers and DNS servers. DCDIAG can be found in Windows Server 2003 Support tools for Windows Server 2003 Servers and it is already included in Windows Server 2008 Servers.

If you have a 2008 Server which is domain joined, running DCDIAG in powershell or CMD will be enough to start tests.

For my script, i decided to execute DCDIAG script with following parameters:

Dcdiag.exe /s: DCNAME >> LOGFILE

I did not use Verbose parameter since it  is breaking down my regex function.

Here is the sample logfile of above command:


Very first thing is to get all DCNames in an array to pass them after s: parameter. That is pretty straight forward process.


AllDCs variable includes all my domain controllers in whole forest. For each DC in that array i will try to execute DCDIAG command:



Now i have a logfile output which includes DCDIAG test results for all domain controllers.

For the first column (ServerName) i create a single PSObject that will pass each DCName: (Please note i have $item variable that includes all my DCs)


Now i need to parse logfile not only for test names but also test results such as “failed” or “passed”.

Therefore i used following regex function to get test names and results. (I got this idea from Chris-Dent)


As you notice I used Trim() for text manipulation. I checked lines for “Starting Test: “ string and trim it. So i assigned actual test name to $TestName variable.

Then i checked for strings “passed” and “failed”. If line matches “passed” i assigned “passed” string to $teststatus variable. If not, i assigned “failed” string to same variable.

At the end of the day i will have two variables $TestStatus and $TestName which includes all test names and results foreach.

The last paragraph is to add additional value to my $results object that i created at the beginning. That means, after ServerName column, i will have additional testname columns such as Advertising, Replication, Service etc.

To format my output with HTML tags, at the beginning of script i added following lines:


Now comes the tough part, creating conditions to colourize rows for each result (failed & passed). Thanks to my Bermudian friend Serkan Varoglu for his great suggestions Smile

Here is how he suggest to colourize:


With $table variable i created tables for the tests that i want to output in HTML table:

I configured $bg parameter as $null, it will be used to configure background html tag.

I created couple of link variables, in the future what i want is to assign related technet article for each failed row. It is actually ready in script, all needed is to insert links.

And then it creates two condition for each test. If row includes “failed” string,

will be red. If not it will stay as green.

with tag, it adds related technet article links.

And the last part is to create header, close table tags and send it via a SMTP server:



In next parts, i will get into details of creating uptime, and repmon reports.

If you want the full code, just drop me an email.

Finally added latest version to Technet Script Gallery. No need to send e-mail to me 🙂


Elder Scrolls Online

I have been introduced with The Elder Scrolls V: Skyrim which is a action role-playing open world video game through Steam. While searching for any open world games, Steam suggested me to try it.

I’m a huge fan of open world games (aka sandbox video games). They give you great flexibility and freedom of a great wide world to explore. Instead of linear games they give you sense of freedom. You don’t need to follow missions one by one, you can just walk for days to explore hidden missions, places, characters.

I think Elder Scrolls V: Skyrim was built on top of Fallout universe. Bethesda learned many lessons from Fallout experience and patch all missing parts while building Skyrim universe. Therefore they created one of the most popular/purchased open world game ever.

I spent 10s of hours with this game and now I heard that Skyrim Online will be available in 2013 !

Skyrim Online will be Massively multiplayer online role-playing game (MMORPG). In MMORPG games, large number of players interact with the world and each other. While you are sleeping, anyone around the world may be inserting or reading data in this world.

I highly doubt that for those who are big fans of Skyrim world will spent most of their life with Elder Scrolls Online.

The Elder Scrolls Online official website

The Elder Scrolls Online The Alliances Cinematic Trailer

And finally, Sneijder agrees to join Galatasaray


When I first heard about transfer rumours for Wesley Sneijder, did not think it was real or somehow possible. I totally agree that Turkish League is not one of the top and excited leagues if you compare it with Spain, English or Germany leagues.

Yeah I know some of great players such as Roberto Carlos, Ortega, George Hagi or Quaresma decided to move Turkey and played for Turkish teams in the recent past but almost all of them were at the end of their career or were not in same performance as before.

Usually worldwide players use Turkey as a last stop in their career. Turkish teams transfer “so-called” great players with huge transfer fees to satisfy fans. It’s a win-win strategy for both Turkish clubs and players. But they can only play one or two years and then leave from Turkey as letting fans down. Of course there are some exceptions like Hagi Smile

This is why I did not believe Wesley transfer news. Since he is 28, played in Real Madrid, Inter and Holland National Team, won Champions League Cup, this transfer is really a success story for Galatasaray Board.

During transfer negotiations between Wesley and Galatasaray, Liverpool’s star Steven Gerrard said Liverpool should sign up Wesley. But at the end of the day it seems because of high tax rates in England, Liverpool could not guarantee fees what Wesley desired.

I hope our emperor Fatih Terim will train Wesley as fast as possible to make him ready for our rivals.



ConfigMgr12 Capture Media–Handle is invalid

If you created Capture Media CD to capture a reference machine, most probably you should execute it from Autorun. If you try to execute it from executable files within media, you will see it under processes but it will not initiate capture wizard.

But one another problem you may face is ‘handle is invalid’ error message.

If you have Symantec Endpoint Protection installed on reference computer and has client management protection enabled, by default it will not allow you to execute programs using AutoRun. Therefore Capture Media will throw “Handle is invalid error”.

To resolve, just disable this specific rule and execute it from scratch.

SCCM – Society of Critical Care Medicine :)

Most of us, even me use SCCM as a official acronym for the Configuration Manager product. But please be aware that it is not official acronym, actually it is owned as a trademark by Society of Critical Care Medicine in USA.

Therefore I will start to replace every SCCM acronym to ConfigMgr in my blog as well Smile