Tag Archives: microsoft

A little while ago I posted a script for enabling users for Lync and settings some settings for that user. That script has been used here ever since I posted it and it has worked like a charm. However there’s always room for improvement, right?. So I have made a function out of it and for the first time (I think) I have even implemented some error handling. The function is also improved quit a bit on the help section and the info that is shown to the user after the function completes. As in the script, this function will enable the user for Lync and set some default settings like Dial Plan, Voice Policy, Conferencing Policy. It also gives you the option to specify a Line URI. The difference is that this function will use the default settings only if nothing else is specified, so you can change the…

Read more

A friend of mine came to me with an interesting powershell challenge today: how can I use powershell to archive and clear event logs? Well, challenge accepted! The reason the challenge arose is due to maintenance he performs on a number of customer servers. Every month he saves each eventlog and clears it manually, a time consuming task if you have more than a few servers. So here’s what I came up with: A powershell function, Rotate-EventLogs, that exports the application, system and security logs to xml files with todays date as filename, then the logs are cleared. The function isn’t really all that advanced, it checks if the folders where the logs will be saved exists, if not it will create them. Then it will export each log to c:eventlogs<logname>%d%m%Y.xml For example the system log exported today would be located at c:eventlogssystem6092012.xml. After the export of the three eventlogs…

Read more

I ran into a rather strange error today when trying to run Group Policy Modeling on a user. Instead of showing me Summary and Settings I received an error stating that The given Key was not present in the dictionary. At first I thought that maybe we had used some Norwegian characters somewhere in a policy, but after some googling it turns out that this is caused by ticking the parent registry container when using the Registry Wizard to create a gpo registry preference. Microsoft has published a kb article about it here: http://support.microsoft.com/kb/2692409 However the resolution they are presenting is useless for most organizations I think. Recreating all registry collections is not an option, at least it wasn’t for us. So here’s how to do it in a less time consuming manor (but it may still take some time): Edit any gpo you have used to set registry settings, navigate…

Read more

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 } But since I already was at it I decided to to a little more, I added some argument handling and a little help file. Here is the result: function Set-ADPhoto ($user,$photopath) { Import-Module active* $error = “The file is bigger than 12KB. Shrink it or choose another file” $file = Get-Item “$photopath” $filesize = $file.length/1KB if ($filesize -gt 12) { Write-Host $error } else {…

Read more

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? That has been an issue for us for some time now. None of our monitoring solutions were able to detect this, so I decided to write a simple powershell script for this. The script uses the RedistributeActiveDatabases.ps1 script to check how many, if any, databases is mounted on a less preferred server. If more than 0 databases is mounted on a less preferred server it sends a mail to a given mail address with how many databases…

Read more

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 🙂 Some title You are now beeing forwarded to https://some.domain> If you are not forwarded automatically, click the above link.

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. But with powershell you can search through the event logs from a command line: Get-EventLog is quite the useful cmdlet. You can specify which log you want to search, a time window, usernames, entrytypes and even computername. If you are a little more experienced with powershell you can even dig down further by piping the command to a where-object cmdlet, for example if you want to see all entries in the system log with the event id…

Read more

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. I could incorporate more in this script, for example sharepoint and lync config, but I figured the script is long enough. If you…

Read more

I wrote this simple little script for enabling users for Lync. It asks for input on name, sipdomain and line uri. The rest is set using variables defined at the start of the script. If you only have one sipdomain you can change the script so that it doesn’t ask for it. Here’s the script in all its glory: $UI = (Get-Host).UI.RawUI $UI.WindowTitle = “Enable lync user” Import-Module Lync #Setting some variables $registrarpool = lyncpool.test.local $csdialplan = DialPlanSIPtrunk $csvoicepolicy = “SIP Trunk Service” $csconferencingpolicy = Conference #Ask for the rest of the information $name = Read-Host “Who do you want to Lync enable?” $sipdomain = Read-Host “Enter SIP domain” $lineuri = Read-Host “Enter line uri” Write-Host “Working…” #Enabling the user for Lync enable-csuser -identity $name -RegistrarPool $registrarpool -SipAddressType UserPrincipalName -SipDomain $sipdomain #Sleep for a few seconds (otherwise the next command might fail) Start-Sleep -s 3 #Setting settings on the user…

Read more

In this guide I will show you how to install and configure a simple Exchange 2010 environment using no gui at all. Installing exchange 2010 without gui may seem kinda nerdy, but it’s quite useful for quickly setting up a test environment for example. Remember to run Windows update prior to the installation. Start powershell as administrator and type: import-module servermanager First we need to install all of the prerequisites: Add-WindowsFeature Web-Metabase, Web-Lgcy-Mgmt-Console, Web-Server, Web-ISAPI-Ext, Web-Metabase, Web-Lgcy-Mgmt-Console, Web-Basic-Auth, Web-ASP, Web-Digest-Auth, Web-Windows-Auth, Web-Dyn-Compression, Web-Net-Ext, RPC-over-HTTP-proxy, AS-NET-Framework, NET-HTTP-Activation We also need to set the NetTcpPortSharing service to automatic start, the command for this is: Set-service NetTcpPortSharing -startuptype automatic If you already haven’t you need to raise the forest functional level to at least Windows Server 2003 native. Before you start to install Exchange you need to prepare your Schema. If you are installing exchange on a domain controller, all you need to…

Read more

10/21