All posts in PowerShell

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

In a recent script I wanted to find out the path to one of the special folders in Windows. Special folders are system folders like “Windows”, “System”, “Desktop”, “MyDocuments” and so on.

Well that’s pretty easy, you can simply use the following line:

[Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])

And from the output you’ll see what SpecialFolders are on your system.

SpecialFolders

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now this is nice but it doesn’t show you where these SpecialFolders are, it just shows the name of them. So try this instead.
$SpecialFolders = @{}
$names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])

foreach($name in $names | sort Name)
{
if($path = [Environment]::GetFolderPath($name))
{
$SpecialFolders[$name] = $path
}
}

 

Now you’ll get a path as well 🙂

SpecialFolders2