Adding a pause to you Powershell scripts

If you have taken a look at some of the scripts I have posted earlier you might have noticed a rather strange line, usually at the end of the script: cmd /c pause | out-null This was actually just to get the script to wait for the user to press a key. It is equivalent to the good ol’ pause in batch scripting. The reason I used this method was that I just didn’t know how to do this in Powershell (yes, I am ashamed)....

September 10, 2012 · nerenther

Cisco escape sequence

I better write this down before I forget it again: ctrl+shift+6 x If this makes absolutely no sense to you I will explain: When you run commands like traceroute, ping and others within Cisco IOS you can abort them. But you can’t use the usual ctrl+c (that would be to logical I guess), you need to press ctrl+shift+6 and THEN press x. There’s probably a good explanation for this, but I still feel that it is horribly cumbersome....

September 3, 2012 · nerenther

Function for locating an email address

Yesterday I was given a relatively easy task: find out who or what has a given email address. As this was within our own Exchange organization it proved to be quite simple: You can achieve the goal with a simple one-liner: get-recipient -ResultSize unlimited | where {$_.emailaddresses -match "email@address.com"} But wouldn’t it be easier to have it in a function? In Powershell, creating functions isn’t all that hard. Basically all you need to do is wrap the command or script block with a function statement, see here:...

August 28, 2012 · nerenther

Function for adding photo in Active Directory

I have always been careful to avoid the really advanced and cool stuff in Powershell, like functions, arrays and such. But as I created the last script it hit me that it would be really cool to have it in a command, like set-adphoto. After some googling I found that funtions aren’t hard at all! Basically all I really had to do with the ad photo import script was to add “function Set-ADPhoto { ” in front of the script and end it with a }...

August 24, 2012 · nerenther

Simple script for adding user photo in Active Directory

It’s been a while since I posted here so I thought it might be time to add some content. This script is a simple script that adds a photo to a user’s active directory user object. It also checks the filesize to prevent users adding large photos (you can of course change this limit). The requirements for this script is the Active Directory module and permission to edit a user object in Active Directory...

August 16, 2012 · nerenther

Check if DAG databases is on preferred server

If you are using DAG in exchange 2010 for high availability on your mailboxes there may be one thing you might have noticed, the databases can fail over to a less preferred server at any time without you noticing. Microsoft have provided you with a script for balancing these databases, RedistributeActiveDatabases.ps1. With this script you can activate the databases on their preferred server again. But how do you know when they have failed over?...

April 30, 2012 · nerenther

Redirecting a webpage using html

The redirect function in IIS 7 and 7.5 is in my experience pretty buggy. More often than not it will send the visitor into an eternal redirect loop. Because of that I have used this simple html code for redirecting, instead of using the built in function in IIS. Use it at your own will, I’m just posting it so I know where to find it the next time I need it 🙂...

February 27, 2012 · nerenther

Grep'ing the eventlog using powershell

If you are used to working with Linux you’re probably familiar with using tail, grep and such for gathering stuff from logs and other files. Those are quite useful tools and work very well when you want to find out e.g. why a user fails to log in. In Windows it’s a little different, if we want to find something in the event logs we have always had to resort to a console....

February 20, 2012 · nerenther

New shop

I have opened up my own spreadshirt shop. Head on over to kemta.spreadshirt.no and take a look. If you’r a geek like me, you should be able to find some cool things there. There’s not too much there at the moment, but I will add more as time goes by 🙂

November 29, 2011 · nerenther

Mass import of users in Active Directory v2 – Powershell time

Earlier I posted a script that created users and homefolders and added the users to specified groups. It also set ntfs permissions on the homefolders. That script used primarily old fashioned stuff, so I sat down and started looking for a neat way to do the same in powershell. The powershell script I came up does a lot more than the last one. Here a little list: Creates OUs Creates users Creates security groups Creates distribution groups Creates mailboxes for all users Add specified users to the correct security and distribution groups Creates a homefolder root folder and shares it Creates a homefolder for each user and sets ntfs permissions Set storage limit on the exchange mailbox database As you can see, it does quite a lot....

October 27, 2011 · nerenther