Sometimes it can be handy to check what devices are live on a network. You can just ping your broadcast address with Windows and that will work (albeit in whatever order the devices respond to you) but of course what if you want to quickly scan another network? You can't ping a broadcast address for a network your PC is not actually on. Don't worry however as it's easily done with a quick command
Simply run this command and you'll find a text file with all the answers (this file will only contain the IP addresses which have responded). Just change the details to suite your network.
FOR /L %i IN (1,1,254) DO ping -n 1 192.168.1.%i | FIND /i "Reply" >> c:\foundyou.txt
The brackets in the command contain the finer details. The first number is the IP you want to start with (in this case 1 so the ping will do 192.168.1.1) and the second number is the incremental amount you want to add to ping the next IP. So dThe 2nd number is 1 so the next IP to ping will be 192.168.1.2. If we were to have put a 2 there then it would be 1 + 2 so the next IP to ping would of been 192.168.1.3. Finally the last number is the last number to get to and stop. In our case it is 254 so we would have ping'd every IP in the subnet of 192.168.1.x/24. If we only wanted to ping 192.168.1-25 then we'd change the last number to 25.
Also just change the file path to somewhere you can actually save files to or you'll get an access is denied error...unless of course you do a Run as administrator for your command prompt. Now while this is running, it's a perfect time to get a quick pint in at the local!
Friday, 6 March 2015
Wednesday, 5 March 2014
Finding empty ports on a Cisco switch
Now I've started working for a new agency that has cisco switches that we look after internally and with most media agencies, there always seems to be desk moves etc. With this in mind it is always important to find free ports on the switches before a move.
Now 95% of our users have laptops so you cannot rely on the port not being active today as the user could be working away from their desk and plug back in using their ethernet cable when they are back.
A very easy way of finding free ports and when they were last used is to login to the cisco switch and run the following command:
Sh int | inc Gig|Last input
This will list all ports on the switch and show their status (connected or not connected) along with the last time data was passed through. As you can see below Port 23 is very much still in use and Port 24 is disconnected and was last used 11 weeks and 5 days ago, so I would say it is safe to re-use this port. Now remember to always check the config of the port before you re-assign the port as it's config could be important and required in the future for some random legacy system etc.
GigabitEthernet2/0/23 is up, line protocol is up (connected)
Hardware is Gigabit Ethernet, address is 5835.d981.9a97 (bia 5835.d981.9a97)
Last input 00:00:04, output 00:00:09, output hang never
GigabitEthernet2/0/24 is down, line protocol is down (notconnect)
Hardware is Gigabit Ethernet, address is 5835.d981.9a98 (bia 5835.d981.9a98)
Last input 11w5d, output 11w5d, output hang never
Now you've saved time by not having to crawl under desks and find unpatched ports and free up ports, you can pop down the pub and have a few well earnt pints!
Now 95% of our users have laptops so you cannot rely on the port not being active today as the user could be working away from their desk and plug back in using their ethernet cable when they are back.
A very easy way of finding free ports and when they were last used is to login to the cisco switch and run the following command:
Sh int | inc Gig|Last input
This will list all ports on the switch and show their status (connected or not connected) along with the last time data was passed through. As you can see below Port 23 is very much still in use and Port 24 is disconnected and was last used 11 weeks and 5 days ago, so I would say it is safe to re-use this port. Now remember to always check the config of the port before you re-assign the port as it's config could be important and required in the future for some random legacy system etc.
GigabitEthernet2/0/23 is up, line protocol is up (connected)
Hardware is Gigabit Ethernet, address is 5835.d981.9a97 (bia 5835.d981.9a97)
Last input 00:00:04, output 00:00:09, output hang never
GigabitEthernet2/0/24 is down, line protocol is down (notconnect)
Hardware is Gigabit Ethernet, address is 5835.d981.9a98 (bia 5835.d981.9a98)
Last input 11w5d, output 11w5d, output hang never
Now you've saved time by not having to crawl under desks and find unpatched ports and free up ports, you can pop down the pub and have a few well earnt pints!
Wednesday, 22 January 2014
Syslogging a Cisco switch
Now when it comes to looking after a large IT estate, it can be a pain to keep track of all those errors and warnings in logs. Most people put alerting in place for their servers and firewalls which is great, however you can never forget those poor switches that carry all that data around your network. If one of those fails then it is back to using carrier pigeons for you!
To configure a cisco switch to send out syslogs to a server you need to first of all enter config mode
tekctrl-3570-01#conf t
Then you need to set the switch to timestamp the logs, otherwise it won't make any sense in your syslog server
tekctrl-3570-01(config)#service timestamps log datetime
You need to then inform the cisco switch where to send the logs to
tekctrl-3570-01(config)#logging x.x.x.x
You then need to configure the level of events the cisco switch will send over. 7 is the most active (debug) and will send EVERYTHING across. I have set this one to 4 (warning) so that any emergencies, alerts, critical errors and warnings are sent over but notification information such as someone plugging a cable into a port is not sent over (because come 17:30 your syslog server will be filled with damn near every good user powering down and disconnecting from the switches!)
tekctrl-3570-01(config)#logging trap 4
The next line will also set the local level of logging for the cisco switch. local7 is the default so we might as well stick with it
tekctrl-3570-01(config)#logging facility local7
Now exit the config mode
tekctrl-3570-01(config)#end
And for f*ck sake save the running config or you'll be kicking yourself (and I'll be kicking you too!) when the switch reloads and all this heavenly syslog glory is lost..
tekctrl-3570-01#copy running-config startup-configDestination filename [startup-config]?
Building configuration...
[OK]
Now confirm the logs are appearing in your syslog server and f*ck off to the pub and let the syslog server deal with all the whining and moaning your Cisco kit is producing
Location:
London, UK
Saturday, 1 June 2013
Showing when a page last updated
A handy little trick I often use to check on the last time a web page was last updated (handy when having to reference the site it check it's activity)
javascript:alert(document.lastModified)
When using Chrome however, you need to manually type this in because when you copy and paste this in, Chrome will remove the javascript: section and therefore you'll just run a needless Google search on "alert(document.lastModified)"
It even works in Android (Chrome for Android does not remove the JavaScript: entry either)
Give it a try and crack open a newly brewed Budweiser to celebrate (and don't forget to check the born date on those bad boys just for consistency)
javascript:alert(document.lastModified)
When using Chrome however, you need to manually type this in because when you copy and paste this in, Chrome will remove the javascript: section and therefore you'll just run a needless Google search on "alert(document.lastModified)"
It even works in Android (Chrome for Android does not remove the JavaScript: entry either)
Give it a try and crack open a newly brewed Budweiser to celebrate (and don't forget to check the born date on those bad boys just for consistency)
Tuesday, 26 March 2013
Restoring deleted items from Public Folders natively
This morning I had a user call up and say that half the meeting room calendars (which are public folders) were empty. I checked via Exchange Management Console and could confirm that there were no items. However under the statistics for the folder, I noticed that it was showing a total deleted items size.
I decided to check this out through ExFolders (Exchange 2010 replacement for PFDAVAdmin) and did come across a problem as I was getting the error "An error occurred while trying to establish a connection to the exchange server. Exception: the Active Directory user wasn't found". To get past this issue open ADSIEDIT and select Configuration from the Well Known Naming Context drop down menu. Then drill down to Configuration> Services> Microsoft Exchange> Domain Name> Administrative Groups> First Administrative Group> and then delete the Servers object. This can sometimes be left behind from old Exchange 2003 installs. As soon as that is gone then ExFolders can continue (please read the "read me" for ExFolders as it does specify to run the reg edit file and also to move ExFolders.exe to your Exchange location\bin\ folder, which is generally in <drive>:\Program Files\Microsoft\Exchange Server\V14\Bin. It will crash otherwise).
After finding one of the folders that had its content deleting I noticed that at the bottom, there is a "normal contents" and "deleted contents" radio buttons. Unsurprisingly, selecting "deleted contents" brings up the list of deleted items. To restore them it is a simple task of selecting the items, right clicking and selecting "restore items". Bingo the items are back and I didn't even need to get out of my chair to get to the backup tapes. Which is handy as it is in the opposite direction to the pub...
I decided to check this out through ExFolders (Exchange 2010 replacement for PFDAVAdmin) and did come across a problem as I was getting the error "An error occurred while trying to establish a connection to the exchange server. Exception: the Active Directory user wasn't found". To get past this issue open ADSIEDIT and select Configuration from the Well Known Naming Context drop down menu. Then drill down to Configuration> Services> Microsoft Exchange> Domain Name> Administrative Groups> First Administrative Group> and then delete the Servers object. This can sometimes be left behind from old Exchange 2003 installs. As soon as that is gone then ExFolders can continue (please read the "read me" for ExFolders as it does specify to run the reg edit file and also to move ExFolders.exe to your Exchange location\bin\ folder, which is generally in <drive>:\Program Files\Microsoft\Exchange Server\V14\Bin. It will crash otherwise).
After finding one of the folders that had its content deleting I noticed that at the bottom, there is a "normal contents" and "deleted contents" radio buttons. Unsurprisingly, selecting "deleted contents" brings up the list of deleted items. To restore them it is a simple task of selecting the items, right clicking and selecting "restore items". Bingo the items are back and I didn't even need to get out of my chair to get to the backup tapes. Which is handy as it is in the opposite direction to the pub...
Labels:
backup,
Exchange,
ExFolder,
PFDAVAdmin,
public folder,
restore,
Server
Location:
Canary Wharf, London E14, UK
Thursday, 21 March 2013
Cannot login to BES Express 5
I was 100% sure all the details were correct and oddly after a few attempts just to make sure, the besadmin account became locked. This meant that it was passing the details through to AD at least so I knew it wasn't broken in that aspect. I had looked through a few forums and noted that some people suggested adding Kerberos authentication to the besadmin account and this will do the trick. I have installed a few BES environments and never had to do this, so I decided to skip that step. I did notice that both passwords contained a £ or #, which are unsupported characters. I changed the besadmin password to not contain the £ and changed the password for each of the services that used the besadmin account on the new BES server. I also entered in the new password into Blackberry Server Configuration> Administrator Service - AD Settings tab and then restarted the server.
Once this rebooted and all the services started up OK, I could happily login and begin to move users across using the Blackberry Transporter Tool.
For more information on unsupported characters in Blackberry service passwords and how to troubleshoot authentication issues please see Blackberry KB19200 and then go to the local for a nice ale and save yourself 1p ;)
Monday, 18 March 2013
M Audio Delta card not working in OpenSUSE 12.3
Now I keep flipping between various Linux distributions. Recently I decided that I will run OpenSUSE 12.3 on my desktop and Ubuntu on my laptop. Now I have an old M Audio Delta 66 sound card, which I have ALWAYS had issues with (not only in Linux but Windows too from Vista upwards) and this was no different with OpenSUSE 12.3. There was no audio at all and I could not change any settings at all in System Settings > Sound (If I tried to load this up, it would crash).I ran lspci and could see the item was listed:
Now I could see the sound card listed (Its the ICE1712 device) so I knew it was running at least. I've never been able to get this to work with pulse audio running so I removed this and installed alsa tools. To install this run the following:
After this has been installed I was able to edit the various inputs I use through the card (I use the Omni Studio expanded unit also). Now it depends on how you have yours set up, though I use the monitor outputs for my M Audio BX-8a speakers (my setup in Yast is listed below and as you can see I just use the DAC outputs, which are the monitor outputs on the soundcard). I also removed Pulseaudio as I no longer required this
I also removed pulse audio since I was no longer using it, however you can leave it installed if you really want (to uninstall just run sudo zypper remove pulseaudio). Now for MP3 support you will need to install the codecs for these as free and open source software is not allowed to package these together. There's two ways to do this:
Simply click on this link and it will install all the relevant codecs you need for multimedia playback (MP3 and DVD etc)
To install all the codecs you need you will first of all need to run the following commands in the terminal:
Add the needed repositories (skip the dvd repo if you don't need DVD playback)
mike@Mike-Suse-PC:~> /sbin/lspci | grep -i audio 02:07.0 Multimedia audio controller: VIA Technologies Inc. ICE1712 [Envy24] PCI Multi-Channel I/O Controller (rev 02) 05:00.1 Audio device: Advanced Micro Devices [AMD] nee ATI RV770 HDMI Audio [Radeon HD 4850/4870]
Now I could see the sound card listed (Its the ICE1712 device) so I knew it was running at least. I've never been able to get this to work with pulse audio running so I removed this and installed alsa tools. To install this run the following:
sudo zypper install alsa-tools
After this has been installed I was able to edit the various inputs I use through the card (I use the Omni Studio expanded unit also). Now it depends on how you have yours set up, though I use the monitor outputs for my M Audio BX-8a speakers (my setup in Yast is listed below and as you can see I just use the DAC outputs, which are the monitor outputs on the soundcard). I also removed Pulseaudio as I no longer required this
I also removed pulse audio since I was no longer using it, however you can leave it installed if you really want (to uninstall just run sudo zypper remove pulseaudio). Now for MP3 support you will need to install the codecs for these as free and open source software is not allowed to package these together. There's two ways to do this:
The Easy way
Simply click on this link and it will install all the relevant codecs you need for multimedia playback (MP3 and DVD etc)
The Terminal way
To install all the codecs you need you will first of all need to run the following commands in the terminal:
Add the needed repositories (skip the dvd repo if you don't need DVD playback)
zypper addrepo -f http://ftp.gwdg.de/pub/linux/packman/suse/12.3/ packman zypper addrepo -f http://opensuse-guide.org/repo/12.3/ dvd
Now this will add in the repositories needed to install all the items you need and keep them up to date also. The next command you need to run will command OpenSUSE to install the various codecs you need:
zypper install libxine2-codecs k3b-codecs ffmpeg lame gstreamer-0_10-plugins-bad gstreamer-0_10-plugins-ugly gstreamer-0_10-plugins-ugly-orig-addon gstreamer-0_10-plugins-ffmpeg libdvdcss2
Now once everything is installed and you have some glorious music playing out, I'd say it would be prime time to grab a fine ale and save yourself 1p ;)
Sunday, 20 January 2013
Time and Date missing from Ubuntu
I've been trying to use linux more and more as the command lines I know have always come in handy on some UNIX servers I've had to look after and macs also. So I am currently running OpenSUSE 12.2 on a laptop and Ubuntu 12.10 on my PC. I'm not sure how I did it, but while I was ripping bits of software out of Ubuntu, the time and date went missing from the top right hand corner of my display. I searched in Unity for Time and Date and alas it was not there.
Now since it was only the indicator that was missing, it was a simple case of re-installing the indicator again. To do this run the following command in the terminal
Now after you have installed this you have two options, either log out and then log back in again (bit too Microsoft-like for me) or you can kill off your unity program, which automatically restarts. To do this run the following command:

As you can see from the screenshot above, it will come back with the PID of the program (number next to the user) and the one you want to kill of is /usr/lib/unity/unity-panel-service. To kill this service off just run the command:
You will see unity close down, refresh and then the time will appear again in the top right hand corner. Now would be a perfect time (no matter what the time now says on your PC) to have a beer.
Now since it was only the indicator that was missing, it was a simple case of re-installing the indicator again. To do this run the following command in the terminal
sudo apt-get install indicator-datetimeNow after you have installed this you have two options, either log out and then log back in again (bit too Microsoft-like for me) or you can kill off your unity program, which automatically restarts. To do this run the following command:
ps -ef | grep unity-panel-serviceAs you can see from the screenshot above, it will come back with the PID of the program (number next to the user) and the one you want to kill of is /usr/lib/unity/unity-panel-service. To kill this service off just run the command:
kill <PID you just discovered using ps -ef, which in my example above it 4643>You will see unity close down, refresh and then the time will appear again in the top right hand corner. Now would be a perfect time (no matter what the time now says on your PC) to have a beer.
Monday, 19 November 2012
Windows 8 not showing your content in Music, Photos and Videos Apps
I recently upgraded to Windows 8 and have found it strange to get used to, from the Win + I to bring up options for apps to getting used to not having the start menu. However the biggest problem I had was opening the My Music, Photos and Video apps and it not showing ANY of my content. I'd read other users having this issue, but with NAS and other network shares etc but mine is stored on a separate local SATA drive. My Libraries were set to view this information and selecting my Music Library showed all this music that I couldn't use in the My Music app.
There is however a way to fix this! The Music, Photos and Video apps not only use your Libraries to gather media data, it also uses the Windows indexing tool. Now considering my media was on another drive and a while back (for whatever reason I cannot actually re-call) I had disabled the Windows Indexing from looking at my other drives so when I upgraded from Win7 to Win8 this area had never been indexed. So I went into Control Panel>Indexing Options>clicked on Modify and selected these extra folders. I then went into Advanced and kicked off a rebuild to hurry things along and start fresh.

After a while of indexing I opened my media Apps in Win8 and the content was all there! Now once you open these applications they begin to then load up previews and thumbnails etc so again once you open the application you must wait a little while (my music took an hour to fully sort itself out) however once its all done everything is there in all its glory. No registry hacks or anything like that, just a slight tweak to what you want indexing. I think I still prefer how Zune works to the new My Music app as I can see much more, however I'm sure it (along with Windows 8) will grow on me. Now time for a beer or a lovely little glass of Glayva to celebrate ;)
There is however a way to fix this! The Music, Photos and Video apps not only use your Libraries to gather media data, it also uses the Windows indexing tool. Now considering my media was on another drive and a while back (for whatever reason I cannot actually re-call) I had disabled the Windows Indexing from looking at my other drives so when I upgraded from Win7 to Win8 this area had never been indexed. So I went into Control Panel>Indexing Options>clicked on Modify and selected these extra folders. I then went into Advanced and kicked off a rebuild to hurry things along and start fresh.
After a while of indexing I opened my media Apps in Win8 and the content was all there! Now once you open these applications they begin to then load up previews and thumbnails etc so again once you open the application you must wait a little while (my music took an hour to fully sort itself out) however once its all done everything is there in all its glory. No registry hacks or anything like that, just a slight tweak to what you want indexing. I think I still prefer how Zune works to the new My Music app as I can see much more, however I'm sure it (along with Windows 8) will grow on me. Now time for a beer or a lovely little glass of Glayva to celebrate ;)
Monday, 21 May 2012
Find email address in Public Folders
Looking after several thousand mailboxes, public folders and distribution groups can sometimes make it difficult for you to keep track on where certain email aliases are assigned.
Now mailboxes, distribution groups and mail contacts are easy as you can add a filter in the Exchange Management Console to find these, however the same cannot be applied for Public folders.
Once again PowerShell comes to the rescue in the form of the Exchange Management Shell. Running the following command will bring up all the details you need:
Get-MailPublicFolder email@address.com | Get-PublicFolder
This command will bring up the name of the public folder along with the parent path so you know exactly where the public folder lives by showing the folder name and the parent path so you can navigate to the folder in question.
Not only do you get to find the public folder you get to learn a little more about Power Shell with the nice "Tip of the day" that appear in the Exchange Management Shell
Now that deserves a beer!
Now mailboxes, distribution groups and mail contacts are easy as you can add a filter in the Exchange Management Console to find these, however the same cannot be applied for Public folders.
Once again PowerShell comes to the rescue in the form of the Exchange Management Shell. Running the following command will bring up all the details you need:
Get-MailPublicFolder email@address.com | Get-PublicFolder
| output from Get-MailPublicFolder |
This command will bring up the name of the public folder along with the parent path so you know exactly where the public folder lives by showing the folder name and the parent path so you can navigate to the folder in question.
Not only do you get to find the public folder you get to learn a little more about Power Shell with the nice "Tip of the day" that appear in the Exchange Management Shell
Now that deserves a beer!
WinSXS taking up space after Service Pack install
I was working on a users desktop the other day who had an SSD installed a while back (back when 128GB were silly prices!) and it could only hold 64GB and it was full (well around 500kb free). This meant her .ost for Outlook couldn’t expand, causing no end of problems for her. Cleaning out temp files and rebuilding the .ost managed to bring back around 2GB which just wasn’t enough really so after hunting around on the drive to find where the rest of the space had gone I found the WinSXS folder. Now this folder was changed from XP to Vista quite a bit from the old .INF files being in there in XP to .mui, .exe’s in Vista and beyond. This folder allows you to run application such as SFC (System File Checker) or when installing additional features and roles in Server 2008 etc. As handy as this is, it can take up a great deal of space, especially when Service Packs are installed (which was the case for this poor user). To help clean this folder up there is a handy tool built into Windows, which can be run from the command prompt (you need to run the command prompt in Elevated Mode to run. To do this, hold down shift and right click on the command prompt icon and select Run as administrator…) which does a nice job of doing it all for you. Please bear in mind after this runs, you won’t be able to roll-back from the Service Packs. The command to run is below:
DISM /online /Cleanup-Image /SpSuperseded
This will take around 20-30minutes to run (depending on the OS and how much space it can reclaim) and can usually bring back around 3-5GB, which is the perfect amount of time to crack open a can of beer
DISM /online /Cleanup-Image /SpSuperseded
This will take around 20-30minutes to run (depending on the OS and how much space it can reclaim) and can usually bring back around 3-5GB, which is the perfect amount of time to crack open a can of beer
| WinSXS size before command was run |
| WinSXS size after command was run |
Saturday, 11 February 2012
Save As PDF not working in Microsoft Office products
Recently I had two issues to sort out in the office. The first was a few users from a group company that were having issues with some powerpoint files that used a truetype font. Powerpoint would get halfway and then crash every singletime. The second issue was in all Microsoft Office products where users would go to create a PDF by using the Save As... feature instead of using the print to option and using cutePDF or the Adobe PDF printers.
Both these faults started happening around the same time (Mid November) but I treated these as seperate issues to start as they came from different companies. I could replicate both errors on my PC and I didn't have any pdf printers installed so it wasn't an issues with either of those products. I decided it might be a Microsoft Office patch and went through each one and still no fix in sight.
I did one last check with another desktop of mine that hadn't had Novembers patches installed and this had no problem at all with either of the reported faults. This gave me somewhere to look, which was in the set of patches released in November and I found the error. MS11-087 was released to fix a zero day fault in Windows that takes advantage of an exploit in the font subsystem (the worm is named Duqu so if you are a creative using TrueType fonts from any site known to Google be careful and make sure your Windows PC is running AV.) What this patch does is change the file permission for a file called t2embed.dll which lives in Windows\system32 (it also lives in the sysWOW64 folder for 64bit systems.)
and for those wanting to know how to how the Duqu worm works:

So to fix this issue you simply have to undo this permission change and give users read access to this file(s if you're on a 64bit system) and the change will kick in straight away. Either that or you can down this .msi from Microsoft that does the exact same thing, just remember to run the command prompt as an administrator and run msiexec to undo the changes, and then relax and have a beer...
Both these faults started happening around the same time (Mid November) but I treated these as seperate issues to start as they came from different companies. I could replicate both errors on my PC and I didn't have any pdf printers installed so it wasn't an issues with either of those products. I decided it might be a Microsoft Office patch and went through each one and still no fix in sight.
I did one last check with another desktop of mine that hadn't had Novembers patches installed and this had no problem at all with either of the reported faults. This gave me somewhere to look, which was in the set of patches released in November and I found the error. MS11-087 was released to fix a zero day fault in Windows that takes advantage of an exploit in the font subsystem (the worm is named Duqu so if you are a creative using TrueType fonts from any site known to Google be careful and make sure your Windows PC is running AV.) What this patch does is change the file permission for a file called t2embed.dll which lives in Windows\system32 (it also lives in the sysWOW64 folder for 64bit systems.)
and for those wanting to know how to how the Duqu worm works:
So to fix this issue you simply have to undo this permission change and give users read access to this file(s if you're on a 64bit system) and the change will kick in straight away. Either that or you can down this .msi from Microsoft that does the exact same thing, just remember to run the command prompt as an administrator and run msiexec to undo the changes, and then relax and have a beer...
Monday, 20 June 2011
SQL Server not starting after an update
So this morning after the patch weekend following Microsofts Patch Tuesday I updated our SQL 2008 R2 server with a security patch (KB2494088) and rebooting the MSSQL Server service refused to work. It would start up but when trying to login all you got in the SSMS(SQL Studio Management Studio) was "login failed for user. Reason: Server is in script upgrade mode. Only administrator can connect at this time"

And after 2 minutes the SQL service would stop. And you're back to square 1. In the event log all i was seeing was the following two errors:
Script level upgrade for database 'master' failed because upgrade step 'sqlagent100_msdb_upgrade.sql' encountered error 598, state 1, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion."
and
Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.
This is where i sh*t myself! After a quick trip i composed myself and decided to try a rebuild of the database. In SQL 2005 and SQL 2008 R2 i know its different that SQL 2000. To do a rebuild in SQL Server 2008 R2 i used the installation media ( you can use the local setup file which lives in C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2) and used the setup.exe file and ran the following command:
SETUP.EXE /ACTION=REBUILDDATABASE /INSTANCENAME=mssqlserver /SQLSYSADMINACCOUNTS="DOMAIN\administrator" "NT AUTHORITY\SYSTEM" "NT SERVICE\MSSQLSERVER" /SAPWD=sapasswordThis ran successfuly (it didnt come up errors once it has run) but alas the same problem, so rebuilding the master database didnt work.
What did work for me was stopping the MSSQL service and starting it up again by using the below commands:
>cd "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\" >sqlservr.exe -c -m -s SQLinstance >sqlcmd -S SERVERNAME,1433 -E Now the switches on sqlserver allow it run not as a service (-c) and in single user mode (-m) and the -s allows you to specifiy the server name. Running SQL in single user mode means no-one can login normally and allows SQL to get on with its upgrade script in peace.
I left this to run for around 15 minutes (if its a busy SQL server you'll see many attempts of other servers/workstations logging in. To stop this i just pulled the network plug as I was working locally. If you need to remote on don't do tis...for obvious reasons :p) and after this finished and I can could see the upgrade script ran successfully I was able to start the SQL service up in the Services.msc and login OK using the SSMS. No need to re-run the patch or roll back and get screamed at by any developers (which could of been the case for me)
After this fault happened I now always allow SQL to start in single user mode after an update/upgrade so it can run these scripts peacefully. Its not really needed and its mainly me siding on the side of caution but it never hurts :)
And after 2 minutes the SQL service would stop. And you're back to square 1. In the event log all i was seeing was the following two errors:
Script level upgrade for database 'master' failed because upgrade step 'sqlagent100_msdb_upgrade.sql' encountered error 598, state 1, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion."
and
Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.
This is where i sh*t myself! After a quick trip i composed myself and decided to try a rebuild of the database. In SQL 2005 and SQL 2008 R2 i know its different that SQL 2000. To do a rebuild in SQL Server 2008 R2 i used the installation media ( you can use the local setup file which lives in C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2) and used the setup.exe file and ran the following command:
SETUP.EXE /ACTION=REBUILDDATABASE /INSTANCENAME=mssqlserver /SQLSYSADMINACCOUNTS="DOMAIN\administrator" "NT AUTHORITY\SYSTEM" "NT SERVICE\MSSQLSERVER" /SAPWD=sapasswordThis ran successfuly (it didnt come up errors once it has run) but alas the same problem, so rebuilding the master database didnt work.
What did work for me was stopping the MSSQL service and starting it up again by using the below commands:
>cd "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\" >sqlservr.exe -c -m -s SQLinstance >sqlcmd -S SERVERNAME,1433 -E Now the switches on sqlserver allow it run not as a service (-c) and in single user mode (-m) and the -s allows you to specifiy the server name. Running SQL in single user mode means no-one can login normally and allows SQL to get on with its upgrade script in peace.
I left this to run for around 15 minutes (if its a busy SQL server you'll see many attempts of other servers/workstations logging in. To stop this i just pulled the network plug as I was working locally. If you need to remote on don't do tis...for obvious reasons :p) and after this finished and I can could see the upgrade script ran successfully I was able to start the SQL service up in the Services.msc and login OK using the SSMS. No need to re-run the patch or roll back and get screamed at by any developers (which could of been the case for me)
After this fault happened I now always allow SQL to start in single user mode after an update/upgrade so it can run these scripts peacefully. Its not really needed and its mainly me siding on the side of caution but it never hurts :)
Friday, 30 July 2010
Create a mac admin via Terminal and turn VNC on
Now a while back we replaced our LANDesk solution with a new appliance at the time called KBOX (made by KACE who are now owned by Dell) and the major benefit to us was the support for Macs. LANDesk though officially supported Apple Macs, was quite weak and we couldn't rely on it. Shame really as LANDesk for PCs was fantastic in my eyes!
Now the problem came a week before. Basically because of various acquisitions and no set standard for the local admin account on Macs, doing a mass roll-out of the new KBOX Agent to 200odd Macs was going to be quite a challenge. So I created a little script (works in Leopard and Tiger but I cannot confirm for Panther or Jaguar ) and packaged it using Package Maker on my Mac (This is part of the developer add-ins that come on the OS X discs)
#!/bin/bash
sudo /usr/bin/dscl . -create /Users/macadmin
sudo /usr/bin/dscl . -create /Users/macadmin UserShell /bin/bash
sudo /usr/bin/dscl . -create /Users/macadmin RealName "macadmin"
sudo /usr/bin/dscl . -create /Users/macadmin UniqueID 550
sudo /usr/bin/dscl . -create /Users/macadmin PrimaryGroupID 20
sudo /usr/bin/dscl . -create /users/macadmin NFSHomeDirectory /Users/macadmin
sudo /usr/bin/dscl . -passwd /Users/macadmin password
sudo /usr/bin/dscl . -append /Groups/admin GroupMembership macadmin
sudo /usr/bin/dscl . -create /Users/macadmin picture "/Library/User Pictures/Sports/8ball.tif"
Now this creates a Mac admin account called....well macadmin! Now I'll walk through what exactly this script does so you're more aware and can customise to your own liking. I have labelled items you can customise for yourself in red.
"sudo /usr/bin/dscl . -create /Users/macadmin" will create a user with the short name for you called macadmin (If you are used to UNIX then you'll know it is limited to 8characters but Macs doesnt care and let you put in whatever you want but for best practise stick to 8characters or below).
"sudo /usr/bin/dscl . -create /Users/macadmin UserShell /bin/bash" Tells OS X that whenever Terminal is used by the user its default shell will be /bin/bash. which is the default for Mac users so it would be best to leave this as it is.
"sudo /usr/bin/dscl . -create /Users/macadmin RealName "macadmin"" Makes the actual login name macadmin (you can also login as the short name too. So for me my short name is mightymd (because my name is longer than 8characters its simply mighty and then my initials) and my RealName is Mike Donaldson.)
"sudo /usr/bin/dscl . -create /Users/macadmin UniqueID 550" and "sudo /usr/bin/dscl . -create /Users/macadmin PrimaryGroupID 20" basically give the account a UniqueID (this is required and starts from 501 for the first account and then 502 for the second account....so I have chosen 550 because its doubtful you will have 49 other local accounts on your macs!) and the PrimaryGroupID is set to 20 by default so I have left that as is.
"sudo /usr/bin/dscl . -create /users/macadmin NFSHomeDirectory /Users/macadmin" creates and sets the users profile to be saved in /Users/macadmin. Obviously if you call your user something else then it would be /Users/username.
"sudo /usr/bin/dscl . -passwd /Users/macadmin password" This will set the macadmin accounts password to password. So you can put in whatever you like for this. But you need to keep this script safe as the password is sitting there in clear text and is risky if everyone can access it.
"sudo /usr/bin/dscl . -append /Groups/admin GroupMembership macadmin" This adds the macadmin user to the admin GroupMembership.
"sudo /usr/bin/dscl . -create /Users/macadmin picture "/Library/User Pictures/Sports/8ball.tif"" This is basically just to give the account a specific login pic. I use the 8ball but you can pick whatever you like. Just take a look in "/Library/User Pictures" and choose your favourite and add it in.

Now you can run that via ARD or save this as a .sh file by using Text or Xcode (i prefer using Xcode just so I can verify my scripts) and then package it using Package Maker and you have your own .pkg file to deploy out whenever you are at the macs in question and bingo!
The next problem I came against was turning on VNC support on the Macs and setting a password for it. Below does this easily enough. It basically turns on VNC, give all local users full access, restarts the agent so the changes are in place and you can specify a password so that when you connect via UltraVNC/RealVNC or any other VNC product it will ask for a password first, so that no-one can just hop on to anyone elses mac without authorisation
#!/bin/sh
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -allowAccessFor -allUsers -privs -all -restart -agent -menu -clientopts -setvnclegacy -vnclegacy yes -setvncpw -vncpw "password"
And then once you've got it all working......have a beer!
Now the problem came a week before. Basically because of various acquisitions and no set standard for the local admin account on Macs, doing a mass roll-out of the new KBOX Agent to 200odd Macs was going to be quite a challenge. So I created a little script (works in Leopard and Tiger but I cannot confirm for Panther or Jaguar ) and packaged it using Package Maker on my Mac (This is part of the developer add-ins that come on the OS X discs)
#!/bin/bash
sudo /usr/bin/dscl . -create /Users/macadmin
sudo /usr/bin/dscl . -create /Users/macadmin UserShell /bin/bash
sudo /usr/bin/dscl . -create /Users/macadmin RealName "macadmin"
sudo /usr/bin/dscl . -create /Users/macadmin UniqueID 550
sudo /usr/bin/dscl . -create /Users/macadmin PrimaryGroupID 20
sudo /usr/bin/dscl . -create /users/macadmin NFSHomeDirectory /Users/macadmin
sudo /usr/bin/dscl . -passwd /Users/macadmin password
sudo /usr/bin/dscl . -append /Groups/admin GroupMembership macadmin
sudo /usr/bin/dscl . -create /Users/macadmin picture "/Library/User Pictures/Sports/8ball.tif"
Now this creates a Mac admin account called....well macadmin! Now I'll walk through what exactly this script does so you're more aware and can customise to your own liking. I have labelled items you can customise for yourself in red.
"sudo /usr/bin/dscl . -create /Users/macadmin" will create a user with the short name for you called macadmin (If you are used to UNIX then you'll know it is limited to 8characters but Macs doesnt care and let you put in whatever you want but for best practise stick to 8characters or below).
"sudo /usr/bin/dscl . -create /Users/macadmin UserShell /bin/bash" Tells OS X that whenever Terminal is used by the user its default shell will be /bin/bash. which is the default for Mac users so it would be best to leave this as it is.
"sudo /usr/bin/dscl . -create /Users/macadmin RealName "macadmin"" Makes the actual login name macadmin (you can also login as the short name too. So for me my short name is mightymd (because my name is longer than 8characters its simply mighty and then my initials) and my RealName is Mike Donaldson.)
"sudo /usr/bin/dscl . -create /Users/macadmin UniqueID 550" and "sudo /usr/bin/dscl . -create /Users/macadmin PrimaryGroupID 20" basically give the account a UniqueID (this is required and starts from 501 for the first account and then 502 for the second account....so I have chosen 550 because its doubtful you will have 49 other local accounts on your macs!) and the PrimaryGroupID is set to 20 by default so I have left that as is.
"sudo /usr/bin/dscl . -create /users/macadmin NFSHomeDirectory /Users/macadmin" creates and sets the users profile to be saved in /Users/macadmin. Obviously if you call your user something else then it would be /Users/username.
"sudo /usr/bin/dscl . -passwd /Users/macadmin password" This will set the macadmin accounts password to password. So you can put in whatever you like for this. But you need to keep this script safe as the password is sitting there in clear text and is risky if everyone can access it.
"sudo /usr/bin/dscl . -append /Groups/admin GroupMembership macadmin" This adds the macadmin user to the admin GroupMembership.
"sudo /usr/bin/dscl . -create /Users/macadmin picture "/Library/User Pictures/Sports/8ball.tif"" This is basically just to give the account a specific login pic. I use the 8ball but you can pick whatever you like. Just take a look in "/Library/User Pictures" and choose your favourite and add it in.
Now you can run that via ARD or save this as a .sh file by using Text or Xcode (i prefer using Xcode just so I can verify my scripts) and then package it using Package Maker and you have your own .pkg file to deploy out whenever you are at the macs in question and bingo!
The next problem I came against was turning on VNC support on the Macs and setting a password for it. Below does this easily enough. It basically turns on VNC, give all local users full access, restarts the agent so the changes are in place and you can specify a password so that when you connect via UltraVNC/RealVNC or any other VNC product it will ask for a password first, so that no-one can just hop on to anyone elses mac without authorisation
#!/bin/sh
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -allowAccessFor -allUsers -privs -all -restart -agent -menu -clientopts -setvnclegacy -vnclegacy yes -setvncpw -vncpw "password"
And then once you've got it all working......have a beer!
Thursday, 29 July 2010
Create new mail contacts from a CSV file for Exchange 2007/2010
Today I had a colleague come to me, asking for help as she had a user asking to have 649 mail contacts created and added to a distribution group by the end of the day.
Now instead of sitting there and slowly adding in each and every single contact individually (which if you've had to do this before in Exchange you'll know it's an absolute nightmare!!) I decided to modify a script I wrote a while back for importing mailboxes from a CSV file.
So the format of the CSV file should be:
For the OUPath you can easily find this out by going into your Active Directory and right clicking on the folder you wish the mail contacts to be imported into, and going to Properties

As you can see in the Object section you can find out the OU Path, by looking at the Canonical name of object:
Once the .CSV file is created and formatted correctly you can use this wonderful little powershell script I wrote:
Import-CSV C:\createnewcontact.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.Email -Name $_.Name -OrganizationalUnit $_.OUpath
}
Now I'll talk you through section by section on what this script does so you're a little more aware (and i can prove I didn't just copy and paste from a website :p)
Now "Import-CSV C:\createnewcontact.csv" basically tells Powershell to import data from the CSV file which lives directly on the C:\ and is called createnewcontact.csv (bare in mind if you call your CSV differently you will need to change this section)
"ForEach-Object"{ allows you to perform an action on each item in the collection (in this case everything between the { }
"New-MailContact" This is kind of self-explainatory to be honest. If you want a new mailbox you put in New-Mailbox and for a new mail contact you use New-MailContact
Now when you run New-MailContact manually into PowerShell it asks you for 2 pieces of information:
So when your PowerShell script runs New-MailContact it still needs this information. So by using "-ExternalEmailAddress$_.Email" you are telling the script that when it gets asks what the -ExternalEmailAddress is the PowerShell sees $_.Email which signifies to it that it should get this information from the Email column ($_. tells it to use the column and the name after it is the column name)
This is the same for -Name $_.Name -OrganizationalUnit $_.OUpath
I'm not the greatest at explaining things so I do apologise. If in doubt just copy exactly what I've done and you'll be fine :)

Pop in the location of the script into Power Shell (or if you're really lazy just drag and drop the script from Explorer into the Power Shell window) and hit enter and watch it run away and create hundreds of mail contacts from your .CSV file in seconds...and then have a beer
Now instead of sitting there and slowly adding in each and every single contact individually (which if you've had to do this before in Exchange you'll know it's an absolute nightmare!!) I decided to modify a script I wrote a while back for importing mailboxes from a CSV file.
So the format of the CSV file should be:
| Name | OUPAth | |
|---|---|---|
| Test User | test.user@domain.com | domain.local/Mail Contacts/Test |
For the OUPath you can easily find this out by going into your Active Directory and right clicking on the folder you wish the mail contacts to be imported into, and going to Properties
As you can see in the Object section you can find out the OU Path, by looking at the Canonical name of object:
Once the .CSV file is created and formatted correctly you can use this wonderful little powershell script I wrote:
Import-CSV C:\createnewcontact.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.Email -Name $_.Name -OrganizationalUnit $_.OUpath
}
Now I'll talk you through section by section on what this script does so you're a little more aware (and i can prove I didn't just copy and paste from a website :p)
Now "Import-CSV C:\createnewcontact.csv" basically tells Powershell to import data from the CSV file which lives directly on the C:\ and is called createnewcontact.csv (bare in mind if you call your CSV differently you will need to change this section)
"ForEach-Object"{ allows you to perform an action on each item in the collection (in this case everything between the { }
"New-MailContact" This is kind of self-explainatory to be honest. If you want a new mailbox you put in New-Mailbox and for a new mail contact you use New-MailContact
Now when you run New-MailContact manually into PowerShell it asks you for 2 pieces of information:
- ExternalEmailAddress
- Name
So when your PowerShell script runs New-MailContact it still needs this information. So by using "-ExternalEmailAddress$_.Email" you are telling the script that when it gets asks what the -ExternalEmailAddress is the PowerShell sees $_.Email which signifies to it that it should get this information from the Email column ($_. tells it to use the column and the name after it is the column name)
This is the same for -Name $_.Name -OrganizationalUnit $_.OUpath
I'm not the greatest at explaining things so I do apologise. If in doubt just copy exactly what I've done and you'll be fine :)
Pop in the location of the script into Power Shell (or if you're really lazy just drag and drop the script from Explorer into the Power Shell window) and hit enter and watch it run away and create hundreds of mail contacts from your .CSV file in seconds...and then have a beer
Subscribe to:
Posts (Atom)