All posts in PowerShell

Its been a little while since I’ve posted on my blog…it’s been a very hectic few months but I’m back and hopefully will be able to provide you guys with some more useful SCOM related things.

Today though its Windows PowerShell as I was required to perform the equivalent of touching a file on a Windows Server. PowerShell doesn’t have a cmdlet specifically for this (that I’m aware of anyway) but we can use the Set-ItemProperty cmdlet and have it update the LastWriteTime property using the current date and time (well actually you could pass it any date and time if you like).

Turns out its pretty easy, just like this…

Set-ItemProperty -Path C:\TestFile.txt -Name LastWriteTime -Value (Get-Date)

 

Hope it helps you.

Today I had a friend message me and ask how he can find all files that have the text (1) or (2) or (3) in the file name using Windows Explorer as he wanted to delete them. First up I must admit to thinking it was a silly question, after all…just type it into the search box right? Wrong, Windows Explorer won’t match on those parenthesis…that was something that I did not know as I really don’t use it all that often.

So I tried it to confirm his findings.

Read more

Today I was having a chat about SCOM Agents with a couple of colleagues and the subject turned to finding out if every server that is in AD actually has an agent installed. I’m certain there are people out there that have their own solution but I thought why not just query AD for the computer objects for these servers and compare that list against the agents in SCOM…should be pretty simple.

If anyone has a better solution (and I’m sure you do)…feel free to share it.

Read more

Today I wanted to extract a list of each IE Favorite I’ve saved, along with the actual URL that it points to. Turns out it’s pretty easy. Here’s that code.

 

gci -path ([Environment]::GetFolderPath(“Favorites”)) -recurse | ? {$_.Length} | % {$_.BaseName; Get-Content $_.FullName -ea silentlycontinue | Select-String ^url=*| %{$_ -replace “^url=”,”” ;””}}

 

The output will list the name of each favorite, along with the actual URL.

In previous posts I talked about how you can get a list of Runbooks from your Orchestrator Server and how you can use PowerShell to trigger a Runbook by supplying only the name of a Runbook and not a GUID.

Today we’re going to see how we can get SCOM to trigger a Runbook as a recovery task to a Alert. For this example we’ll use the “Health Service HeartBeat Failure” monitor. The idea here is that when this alert is received, we’ll trigger our Runbook to try and fix this issue. There’s a fair bit involved, so let’s get started:

 

Read more

I’ve seen a lot of posts on the Internet describing how you can use Orchestrator to trigger a Runbook when a condition is met. For example, Orchestrator can poll SCOM for a specific event and when it occurs it can trigger a Runbook . But what about when you want to trigger a Runbook from a different source? So today I took a look at how I could use PowerShell to trigger a Runbook. Now I have seen some posts describing how to extract the GUID of a Runbook and use that to start the Runbook. I’m not going to do that, I’m going to start a Runbook using only the name of the Runbook which I think is much easier for people to identify with a name, not a GUID. But hey, if you want to use the GUID, feel free to skip the rest of my post and head off to an example from Microsoft here: http://msdn.microsoft.com/en-us/library/hh921685.aspx.

Read more