Output Active Directory Lastlogontimestamp in readable format using PowerShell

If, like me, you’re stuck on Windows 2003 AD you are limited as to which cmdlets you can use.

I had a need to find out the last logon time for a bunch of users, so I put together this function (which I shamelessly borrowed from some where on the internet) and decided to post it up here so I could find it again if I needed it.

function Convert-IADSLargeInteger([object]$LargeInteger){ 

	$type = $LargeInteger.GetType() 
	$highPart = $type.InvokeMember("HighPart","GetProperty",$null,$LargeInteger,$null) 
	$lowPart = $type.InvokeMember("LowPart","GetProperty",$null,$LargeInteger,$null) 

	$bytes = [System.BitConverter]::GetBytes($highPart) 
	$tmp = New-Object System.Byte[] 8 
		[Array]::Copy($bytes,0,$tmp,4,4) 
	$highPart = [System.BitConverter]::ToInt64($tmp,0) 
	$bytes = [System.BitConverter]::GetBytes($lowPart) 
	$lowPart = [System.BitConverter]::ToUInt32($bytes,0) 

	$lowPart + $highPart 
}

$strLDAP = [String] ("LDAP://<ldap path to user>")
$user = [ADSI] $strLDAP
$lastLogon = [DateTime]::FromFileTime([Int64]::Parse($(Convert-IADSLargeInteger $user.lastlogontimestamp.value))) 

write-host ($user.displayname + " last logged on at " + $strLastLogon)

Thanks to whoever wrote the function initially, I have forgotten where I found it.

Vbscript: Output specific users mailbox sizes under Exchange 2000/2003 to csv

What does it do?
This script generates a CSV file containing a users name, exchange server, mailbox size and total number of items. It queries Active Directory to find out which mailbox server the user lives on, then goes and finds the total size of their mailbox.

How do I use it?
1. Edit the vbs file and change the strLDAPString to suit your environment
2. Provide a list of users (one AD user name per line) in the userlist.txt file
3. Run this script.
4. Open CSV file


'This VBS script queries a list of users and outputs a CSV file containing their mailbox sizes
'It is designed for Exchange 2000/2003. 2007 lets you do the same thing a lot easier with Powershell
'Written 07/10/2010 by Burnsie
'

'User Configurable settings
'This string contains your base domain LDAP string
strLDAPString =LDAP://dc=YOUR,dc=WINDOWS,dc=DOMAIN,dc=com

'Declare variables
Dim oSession
Dim oInfoStores
Dim oInfoStore
Dim StorageUsed
Dim NumMessages
Dim strProfileInfo
Dim sMsg

'Input and Output files
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")

'Input file (Change this if you change the input file name)
Set ifile = iFSO.OpenTextFile("userlist.txt")

'Output file
Set ofile = iFSO.CreateTextFile("Mailbox Details.csv")
ofile.writeline "UserName,FullName,Exchange Server,Storage Used (Bytes),Total Items"

'Set up AD stuff
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")

'Loop through each user one by one.
Do until ifile.AtEndOfLine
struser = ifile.ReadLine

'Connect to AD and find out where the users mailbox is located. Also grabs a lot of other details.
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
'Change this if you change the domain
objCommand.CommandText = _
"SELECT Name, adspath FROM '" & strLDAPString & "' WHERE objectCategory='user' " & "AND sAMAccountName='" & struser & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
strpath = objRecordSet.Fields("ADsPath").Value
set objuser = GetObject(strPath)

'If there is no error, then get the details.
If Err.Number = 0 then
strExchangeServer = (Mid(objuser.msExchHomeServerName,(InStrRev(objuser.msExchHomeServerName,"=")+ 1)))
strFullName = objuser.fullname
Else
wscript.echo "Error User Account May Not Exist or Corrupt AD Info For Account"
end if
objConnection.Close

On Error Resume Next

'Create MAPI Session object.
Set oSession = CreateObject("MAPI.Session")
if Err.Number <> 0 Then
sMsg = "Error creating MAPI.Session."
sMsg = sMsg & "Make sure CDO 1.21 is installed. (Run it on an Exchange server is probably easiest)"
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
End If

'Build logon string
strProfileInfo = strExchangeServer & vbLf & strUser

'Log on to mailbox
oSession.Logon , , False, True, , True, strProfileInfo
if Err.Number <> 0 Then
Set oSession = Nothing
End If

'Grab the information stores.
Set oInfoStores = oSession.InfoStores
if Err.Number <> 0 Then

Set oInfoStores = Nothing
Set oSession = Nothing
End If

'Loop through information stores to find the user's mailbox.
For Each oInfoStore In oInfoStores
If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then
'&HE080003 = PR_MESSAGE_SIZE
StorageUsed = oInfoStore.Fields(&HE080003)
if Err.Number <> 0 Then
sMsg = "Error retrieving PR_MESSAGE_SIZE: "
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
WScript.Echo "Server: " & obArgs.Item(0)
WScript.Echo "Mailbox: " & obArgs.Item(1)
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
End If

'&H33020003 = PR_CONTENT_COUNT
NumMessages = oInfoStore.Fields(&H36020003)

if Err.Number <> 0 Then

sMsg = "Error Retrieving PR_CONTENT_COUNT: "
sMsg = sMsg & Err.Number & " " & Err.Description
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
End If

strInfoStore = oInfoStore.Name
strStorageUsed = StorageUsed
strTotalItems = NumMessages
End If
Next

' Log off.
oSession.Logoff

' Clean up memory.
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing

'Echo to screen for people who are impatient and like to see what is going on
wscript.echo strUser &","& strFullName &","& strExchangeServer &"," & strStorageUsed &","& strTotalItems

'Write to CSV file
ofile.writeline strUser &","& strFullName &","& strExchangeServer &"," & strStorageUsed &","& strTotalItems

loop

'Clean up memory and variables
ifile.close
ofile.close
set ifile = nothing
set ofile = nothing
set wsfile = nothing

How to import your Bookmarks to Safari

So you’ve made the switch to the Safari web browser; congrats! But what about your bookmarks? If you have a rather large list of bookmarked websites then you’ll need to import them!

The following method demonstrates how to export your bookmarks from Firefox and import them using Safari.

Step 1: Export bookmarks from Firefox

The first step requires you to export your bookmarks from Firefox. Fortunately this is fairly simple process. Simply select the Bookmarks menu item, then select “Organize Bookmarks”.

Next select the “Import and Backup” dropdown and select “Export HTML”.
When prompted, save this file to your hard drive (desktop is fine for now).

That’s it! You’ve successfully exported your bookmarks from Firefox to a standard .html file.

Step 2: Import your bookmarks into Safari

Next we need to import this file back into Safari. Now for me, the primary menu toolbar wasn’t enabled and I don’t believe it’s enabled by default. If you can’t see menu bar with “File”, “Edit”, “View” etc, then you’ll need to enable this menu bar. You can do this by selecting the cog menu icon on the right of the browser, and selecting “Show Menu Bar”.

Once you’ve got the menu bar activated, simply select “File” then “Import Bookmarks” and browse to your desktop where you saved the Firefox bookmark export!

That’s it! You’ve successfully imported your bookmarks from Firefox. You can now drop and drag your bookmarks to your preference!

I dragged my most used bookmarks to the “Bookmark Bar” in Safari which allows me to quickly access the bookmarks I used most.

Error 0X80040201 while sending email

I recently had issues with an outlook error “0X80040201″ and for the life of me I couldn’t fix it.

However after much distress I was able to uncover what the problem was. I recently went from an Exchange 2007 environment to a IMAP environment and hence some of my contacts were corrupted. If I tried to send an email to anyone from my old exchange contact list – the email would fail; hence the error 0X80040201.

Simply creating new contacts in Outlook for the people I wanted to send emails too, fixed this issue!

cisvc errors on CRM 4.0 install on Windows 2008

I recently had the joy of installing Microsoft’s CRM 4.0 on Windows 2008. One of its prerequesitits is for the server “cisvc.exe” to be started. I had no idea what this meant.

Luckly I managed to get it working by installed the “file server role” (tick the indexing service in the role service section) using the new Windows 2008 server manager. Once the “file server role” was installed, the cisvc service was started and my CRM 4.0 could install!

Hooray!

Downgrade from IE8 to IE7

So you’ve tried Internet Explorer 8 (IE8) and you’re not impressed. Lucky for you there’s a quick solution to downgrade back to trusty old IE7!

Windows XP Solution
1) Click the Start menu, control panel
2) From the control panel select “Add/Remove programs”
3) Find Internet Explorer 8 and proceed to uninstall it.

After the uninstall is complete you’ll be able to use IE8.

Windows Vista Solution
1) Click the Start menu then select control panel
2) From the control panel select “Programs and Features” (Or Programs)
3) Click “View installed updates” on the left

(wait for it to load .. it does take a few minutes. Note the bar at the top of the screen)

4) Find “Windows Internet Explorer 8″, select it and use the “Uninstall button” at the top of the list.

uninstall-ie8-1

uninstall-ie8-2

uninstall-ie8-1

Vista NTLM Setting

A few users have reportedly had troubles with accessing storage devices that require NTLM authentication. For those running vista, you may or may not know that it only uses NTLMv2 authentication and therefore it won’t work.

To get your storage device to work with Vista, you can enable your Windows Vista PC to use both NTLM and NTLMv2 authentcation, in order to communicate with older SAN devices.

Solution

  1. Click the Start Menu, then “Run”
  2. Type “secpol.msc”
  3. Select Local Policies
  4. Select Security Options
  5. Find Network Security: LAN Manager
  6. From the drop down list, select: “Send LM & NTLM – use NTLMv2 session security if negotiated”

Now you should be able to communiate with older SAN devices in Windows Vista!

WinXP Taskbar Double

The problem:
Your windows XP taskbar is showing as two rows or it has doubled in size.

The solution:
Lucky for you, fixing this problem is dead simple.

First of all, make sure your taskbar is NOT locked.
1) Right click the taskbar (Make sure you “right click” a blank space, that is, don’t right click a running program)
2) Ensure that “Lock the Taskbar” is NOT ticked.

Now you need to reduce the size of your taskbar.
1) Seen the line to the right of the taskbar? (It’s either dotted or a straight line)
2) Put your mouse over this line until your mouse cursor shows <-->
3) Drag that sucker down!

It may take you a few times to get it right. Once you’ve got a single row task bar, you can re-arrange your toolbar sections (quicklaunch etc)

Windows Updates Won’t Install

I’ve seen this problem a few times, whereby you will be in the middle of doing a Windows Update and right after the updates have downloaded, they will refuse to be installed – often freezing and not showing any sign of further progress.

Here are a few solutions that are known to work.

Solution 1 – Reinstalling Windows Installer 3.1
Try installing a fresh new copy of Windows Installer 3.1. (Download it here). The Windows Installer is an application installation and configuration service, and is used by a number of Microsoft products to install applications on your computer.

Solution 2
If you are trying to install Updates via the Windows XP update agent (found in the start menu), try stopping the Agent service and then run Windows update through your web browser (Internet Explorer).

To do this, you must first stop the Automatic Update Server.

1) Click on your Start Menu, then Run
2) Type: services.msc
3) Find the row that says “Automatic Updates”, right click it and select “stop”.
4) Close the windows
5) Launch Internet Explorer and select the Tools menu, then “Windows Update”.
6) Proceed to run a Microsoft Windows Update

Good luck!

Cannot scroll up in Google Chrome using certain touch pads

I wasn’t able to scroll up using my HP Notebook touchpad in Chrome. I downloaded and installed this patch and it resolved it straight away. (I was using Google Chrome v0.2.149.30 at the time)

The patch is available here: http://users.ecs.soton.ac.uk/pjt2v07/chrome/ (Thanks to Paul for writing this fix)

Things to note:
You need to run this patch from the folder that contains the file chrome.dll. For me it was located in the following path (On Windows Vista)
C:\Users\<>\AppData\Local\Google\Chrome\Application.2.149.30

Google Chrome Error 0X00000005

You’ve heard the hype, seen the funky screenshots and want to get in on the action. So you download and install Google Chrome, only to find an error appear stating;

The application failed to initialize properly (0×00000005). Press Ok to terminate application.

Solution 1
This error is most likely caused due to your system not having the Microsoft.NET framework. Download it here.

Solution 2
It’s also been noted that this problem occurs to an issue with Chrome and Symantec Endpoint Protection. Try removing Symantec Endpoint Protection via the “Add/Remove Programs” control panel section, and see if the error goes away.

Cannot remove ytoolbar_title_my_add_disable

If you’ve noticed a weird bar that sits on your screen and mentions something like “ytoolbar_title_my_add_disable”, and you can’t seem to remove it; the you’ve most likely have a broken yahoo toolbar. The best remedy is to simply remove the Yahoo Toolbar.

There’s a few things you can do.

1) If you use Firefox; click the tools menu > then Extensions > Scroll until you see “Yahoo! Toolbar extension”, select this item and click “Uninstall”. Then restart Firefox”.

2) If you use Internet Explorer, you may also uninstall the Yahoo Toolbar by visiting your computers “Add/Remove Programs” section under the Control Panel.

« Previous Entries