Powershell Script: ActiveSync Properties

2 04 2010

activesync-logo

Our good friend StevieMac over at The Scripting Guy wrote a nice powershell script that allows Exchange Administrators to view the ActiveSync properties of a user’s mailbox in a nice looking GUI window:

activesync1

function GenerateForm {

########################################################################

# Generated On: 12/22/2008 4:04 PM

# Generated By: StevieMac@thescriptingguy.com

########################################################################

Function getInfo()

{

Get-ActiveSyncDeviceStatistics -Mailbox $txtQNumber.text -ShowRecoveryPassword:$true | ForEach-Object{

if ($_.DeviceID -ne $null){$txtDeviceID.text = $_.DeviceID}

if ($_.FirstSyncTime -ne $null){$txtFirstSyncTime.text = $_.FirstSyncTime}

if ($_.DeviceModel -ne $null){$txtModel.text = $_.DeviceModel}

if ($_.DeviceIMEI -ne $null){$txtIMEI.text = $_.DeviceIMEI}

if ($_.LastPolicyUpdateTime -ne $null){$txtLastPolicyUpdate.text = $_.LastPolicyUpdateTime}

if ($_.LastSyncAttemptTime -ne $null){$txtLastSyncAttempt.text = $_.LastSyncAttemptTime}

if ($_.LastSuccessSync -ne $null){$txtLastSuccessfulSync.text = $_.LastSuccessSync}

if ($_.DevicePhoneNumber -ne $null){$txtPhoneNumber.text = $_.DevicePhoneNumber}

if ($_.DeviceOS -ne $null){$txtDeviceOS.text = $_.DeviceOS}

if ($_.RecoveryPassword -eq $null){$txtRecoveryPassword.text = 'No Password Set'}

if ($_.RecoveryPassword -ne $null){$txtRecoveryPassword.text = $_.RecoveryPassword}

}

}

 

#region Import the Assembles

[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null

#endregion

 

#region Generated Form Objects

$frmActiveSync = New-Object System.Windows.Forms.Form

$txtDeviceOS = New-Object System.Windows.Forms.TextBox

$lblDeviceOS = New-Object System.Windows.Forms.Label

$txtRecoveryPassword = New-Object System.Windows.Forms.TextBox

$txtLastPolicyUpdate = New-Object System.Windows.Forms.TextBox

$txtLastSuccessfulSync = New-Object System.Windows.Forms.TextBox

$txtLastSyncAttempt = New-Object System.Windows.Forms.TextBox

$txtFirstSyncTime = New-Object System.Windows.Forms.TextBox

$txtIMEI = New-Object System.Windows.Forms.TextBox

$txtDeviceID = New-Object System.Windows.Forms.TextBox

$txtPhoneNumber = New-Object System.Windows.Forms.TextBox

$txtModel = New-Object System.Windows.Forms.TextBox

$lblRecoveryPassword = New-Object System.Windows.Forms.Label

$lblLastPolicyUpdate = New-Object System.Windows.Forms.Label

$lblLastSuccessful = New-Object System.Windows.Forms.Label

$lblLastSyncAttempt = New-Object System.Windows.Forms.Label

$lblFirstSync = New-Object System.Windows.Forms.Label

$lblIMEI = New-Object System.Windows.Forms.Label

$lblDeviceID = New-Object System.Windows.Forms.Label

$lblPhoneNumber = New-Object System.Windows.Forms.Label

$lblModel = New-Object System.Windows.Forms.Label

$txtQNumber = New-Object System.Windows.Forms.TextBox

$btnList = New-Object System.Windows.Forms.Button

#endregion Generated Form Objects

 

#----------------------------------------------

#Generated Event Script Blocks

#----------------------------------------------

#Provide Custom Code for events specified in PrimalForms.

$btnList.Add_Click({getInfo})

 

#----------------------------------------------

#region Generated Form Code

$frmActiveSync.Text = 'List Active Sync User Information'

$frmActiveSync.Name = 'frmActiveSync'

$frmActiveSync.StartPosition = 1

$frmActiveSync.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 464

$System_Drawing_Size.Height = 328

$frmActiveSync.ClientSize = $System_Drawing_Size

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 214

$System_Drawing_Size.Height = 20

$txtDeviceOS.Size = $System_Drawing_Size

$txtDeviceOS.DataBindings.DefaultDataSourceUpdateMode = 0

$txtDeviceOS.ReadOnly = $True

$txtDeviceOS.Name = 'txtDeviceOS'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 67

$txtDeviceOS.Location = $System_Drawing_Point

$txtDeviceOS.TabIndex = 21

 

$frmActiveSync.Controls.Add($txtDeviceOS)

 

$lblDeviceOS.TabIndex = 20

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 100

$System_Drawing_Size.Height = 23

$lblDeviceOS.Size = $System_Drawing_Size

$lblDeviceOS.Text = 'Operating System'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 70

$lblDeviceOS.Location = $System_Drawing_Point

$lblDeviceOS.DataBindings.DefaultDataSourceUpdateMode = 0

$lblDeviceOS.Name = 'lblDeviceOS'

 

$frmActiveSync.Controls.Add($lblDeviceOS)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtRecoveryPassword.Size = $System_Drawing_Size

$txtRecoveryPassword.DataBindings.DefaultDataSourceUpdateMode = 0

$txtRecoveryPassword.ReadOnly = $True

$txtRecoveryPassword.Name = 'txtRecoveryPassword'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 284

$txtRecoveryPassword.Location = $System_Drawing_Point

$txtRecoveryPassword.TabIndex = 19

 

$frmActiveSync.Controls.Add($txtRecoveryPassword)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtLastPolicyUpdate.Size = $System_Drawing_Size

$txtLastPolicyUpdate.DataBindings.DefaultDataSourceUpdateMode = 0

$txtLastPolicyUpdate.ReadOnly = $True

$txtLastPolicyUpdate.Name = 'txtLastPolicyUpdate'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 257

$txtLastPolicyUpdate.Location = $System_Drawing_Point

$txtLastPolicyUpdate.TabIndex = 18

 

$frmActiveSync.Controls.Add($txtLastPolicyUpdate)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtLastSuccessfulSync.Size = $System_Drawing_Size

$txtLastSuccessfulSync.DataBindings.DefaultDataSourceUpdateMode = 0

$txtLastSuccessfulSync.ReadOnly = $True

$txtLastSuccessfulSync.Name = 'txtLastSuccessfulSync'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 230

$txtLastSuccessfulSync.Location = $System_Drawing_Point

$txtLastSuccessfulSync.TabIndex = 17

 

$frmActiveSync.Controls.Add($txtLastSuccessfulSync)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtLastSyncAttempt.Size = $System_Drawing_Size

$txtLastSyncAttempt.DataBindings.DefaultDataSourceUpdateMode = 0

$txtLastSyncAttempt.ReadOnly = $True

$txtLastSyncAttempt.Name = 'txtLastSyncAttempt'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 203

$txtLastSyncAttempt.Location = $System_Drawing_Point

$txtLastSyncAttempt.TabIndex = 16

 

$frmActiveSync.Controls.Add($txtLastSyncAttempt)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtFirstSyncTime.Size = $System_Drawing_Size

$txtFirstSyncTime.DataBindings.DefaultDataSourceUpdateMode = 0

$txtFirstSyncTime.ReadOnly = $True

$txtFirstSyncTime.Name = 'txtFirstSyncTime'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 176

$txtFirstSyncTime.Location = $System_Drawing_Point

$txtFirstSyncTime.TabIndex = 15

 

$frmActiveSync.Controls.Add($txtFirstSyncTime)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtIMEI.Size = $System_Drawing_Size

$txtIMEI.DataBindings.DefaultDataSourceUpdateMode = 0

$txtIMEI.ReadOnly = $True

$txtIMEI.Name = 'txtIMEI'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 149

$txtIMEI.Location = $System_Drawing_Point

$txtIMEI.TabIndex = 14

 

$frmActiveSync.Controls.Add($txtIMEI)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtDeviceID.Size = $System_Drawing_Size

$txtDeviceID.DataBindings.DefaultDataSourceUpdateMode = 0

$txtDeviceID.ReadOnly = $True

$txtDeviceID.Name = 'txtDeviceID'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 122

$txtDeviceID.Location = $System_Drawing_Point

$txtDeviceID.TabIndex = 13

 

$frmActiveSync.Controls.Add($txtDeviceID)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtPhoneNumber.Size = $System_Drawing_Size

$txtPhoneNumber.DataBindings.DefaultDataSourceUpdateMode = 0

$txtPhoneNumber.ReadOnly = $True

$txtPhoneNumber.Name = 'txtPhoneNumber'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 93

$txtPhoneNumber.Location = $System_Drawing_Point

$txtPhoneNumber.TabIndex = 12

 

$frmActiveSync.Controls.Add($txtPhoneNumber)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 215

$System_Drawing_Size.Height = 20

$txtModel.Size = $System_Drawing_Size

$txtModel.DataBindings.DefaultDataSourceUpdateMode = 0

$txtModel.ReadOnly = $True

$txtModel.Name = 'txtModel'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 207

$System_Drawing_Point.Y = 40

$txtModel.Location = $System_Drawing_Point

$txtModel.TabIndex = 11

 

$frmActiveSync.Controls.Add($txtModel)

 

$lblRecoveryPassword.TabIndex = 10

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblRecoveryPassword.Size = $System_Drawing_Size

$lblRecoveryPassword.Text = 'Recovery Password'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 287

$lblRecoveryPassword.Location = $System_Drawing_Point

$lblRecoveryPassword.DataBindings.DefaultDataSourceUpdateMode = 0

$lblRecoveryPassword.Name = 'lblRecoveryPassword'

 

$frmActiveSync.Controls.Add($lblRecoveryPassword)

 

$lblLastPolicyUpdate.TabIndex = 9

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblLastPolicyUpdate.Size = $System_Drawing_Size

$lblLastPolicyUpdate.Text = 'Last Policy Update Time'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 260

$lblLastPolicyUpdate.Location = $System_Drawing_Point

$lblLastPolicyUpdate.DataBindings.DefaultDataSourceUpdateMode = 0

$lblLastPolicyUpdate.Name = 'lblLastPolicyUpdate'

 

$frmActiveSync.Controls.Add($lblLastPolicyUpdate)

 

$lblLastSuccessful.TabIndex = 8

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblLastSuccessful.Size = $System_Drawing_Size

$lblLastSuccessful.Text = 'Last Successful Sync Time'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 233

$lblLastSuccessful.Location = $System_Drawing_Point

$lblLastSuccessful.DataBindings.DefaultDataSourceUpdateMode = 0

$lblLastSuccessful.Name = 'lblLastSuccessful'

 

$frmActiveSync.Controls.Add($lblLastSuccessful)

 

$lblLastSyncAttempt.TabIndex = 7

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblLastSyncAttempt.Size = $System_Drawing_Size

$lblLastSyncAttempt.Text = 'Last Sync Attempt Time'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 206

$lblLastSyncAttempt.Location = $System_Drawing_Point

$lblLastSyncAttempt.DataBindings.DefaultDataSourceUpdateMode = 0

$lblLastSyncAttempt.Name = 'lblLastSyncAttempt'

 

$frmActiveSync.Controls.Add($lblLastSyncAttempt)

 

$lblFirstSync.TabIndex = 6

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblFirstSync.Size = $System_Drawing_Size

$lblFirstSync.Text = 'First Sync Time'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 179

$lblFirstSync.Location = $System_Drawing_Point

$lblFirstSync.DataBindings.DefaultDataSourceUpdateMode = 0

$lblFirstSync.Name = 'lblFirstSync'

 

$frmActiveSync.Controls.Add($lblFirstSync)

 

$lblIMEI.TabIndex = 5

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblIMEI.Size = $System_Drawing_Size

$lblIMEI.Text = 'IMEI'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 152

$lblIMEI.Location = $System_Drawing_Point

$lblIMEI.DataBindings.DefaultDataSourceUpdateMode = 0

$lblIMEI.Name = 'lblIMEI'

 

$frmActiveSync.Controls.Add($lblIMEI)

 

$lblDeviceID.TabIndex = 4

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblDeviceID.Size = $System_Drawing_Size

$lblDeviceID.Text = 'Device ID'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 125

$lblDeviceID.Location = $System_Drawing_Point

$lblDeviceID.DataBindings.DefaultDataSourceUpdateMode = 0

$lblDeviceID.Name = 'lblDeviceID'

 

$frmActiveSync.Controls.Add($lblDeviceID)

 

$lblPhoneNumber.TabIndex = 3

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblPhoneNumber.Size = $System_Drawing_Size

$lblPhoneNumber.Text = 'Phone Number'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 96

$lblPhoneNumber.Location = $System_Drawing_Point

$lblPhoneNumber.DataBindings.DefaultDataSourceUpdateMode = 0

$lblPhoneNumber.Name = 'lblPhoneNumber'

 

$frmActiveSync.Controls.Add($lblPhoneNumber)

 

$lblModel.TabIndex = 2

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 182

$System_Drawing_Size.Height = 23

$lblModel.Size = $System_Drawing_Size

$lblModel.Text = 'Model'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 12

$System_Drawing_Point.Y = 43

$lblModel.Location = $System_Drawing_Point

$lblModel.DataBindings.DefaultDataSourceUpdateMode = 0

$lblModel.Name = 'lblModel'

 

$frmActiveSync.Controls.Add($lblModel)

 

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 100

$System_Drawing_Size.Height = 20

$txtQNumber.Size = $System_Drawing_Size

$txtQNumber.DataBindings.DefaultDataSourceUpdateMode = 0

$txtQNumber.Text = 'Enter Users Alias'

$txtQNumber.Name = 'txtQNumber'

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 95

$System_Drawing_Point.Y = 15

$txtQNumber.Location = $System_Drawing_Point

$txtQNumber.TabIndex = 1

 

$frmActiveSync.Controls.Add($txtQNumber)

 

$btnList.TabIndex = 0

$btnList.Name = 'btnList'

$System_Drawing_Size = New-Object System.Drawing.Size

$System_Drawing_Size.Width = 75

$System_Drawing_Size.Height = 23

$btnList.Size = $System_Drawing_Size

$btnList.UseVisualStyleBackColor = $True

 

$btnList.Text = 'List Info'

 

$System_Drawing_Point = New-Object System.Drawing.Point

$System_Drawing_Point.X = 13

$System_Drawing_Point.Y = 13

$btnList.Location = $System_Drawing_Point

$btnList.DataBindings.DefaultDataSourceUpdateMode = 0

$btnList.add_Click($btnList_OnClick)

 

$frmActiveSync.Controls.Add($btnList)

 

#endregion Generated Form Code

 

#Show the Form

$frmActiveSync.ShowDialog()| Out-Null

 

} #End Function

 

#Call the Function

GenerateForm

[ The Scripting Guy ]





Use Excel to create easy batch jobs

25 08 2009

Do you have to run a command on several servers remotely?  You can enter each command separately, but every good admin should know how to make life easier for him/her self.  For example, I wanted to use the psloggedon.exe tool to find out who was logged in to all the servers I manage (about 150).  Naturally, I could log into each server, check the Terminal Server Manager, and go on the next, but who wants to do that? 

The PSTool – psloggedon.exe is a nice little utility that I can run from my command prompt, and have it query a remote computer, returning who is logged on to that server.  So, starting in Excel (I already had a list of all the servers), I pasted the list of servers in the C column.

Next, in Column A, I entered “psloggedon.exe” – the name of the executable I want to run.  in Column B, I put a “ \\” – note the space in front of the \\.  In column E, I entered my first switch, “ –l” – and in column F, a second switch “ –x” again, note the spaces before the switches.

 image image

Now, to bring the whole thing together.  I LOVE the command Concatenate. 

image

In column G, I entered =concatenate(A1,B1,C1,D1,E1)

image

This will combine all the columns together (now you know why the spaces were above) for your final command.

image

You can now select column G, and copy and paste it into notepad, and save it as a .bat file.  You now have an easily made bat file, using Excel.





Export Outlook Contact Pictures

21 08 2009

I recently made a mistake, and deleted the folder where I kept all the original headshots of all my contacts.  Don’t ask me why I keep them, I just do… I know I have them in Outlook, but I like to have the originals also.  Anyway, I wanted a way to export the picture from Outlook, back into the file system.  Well, I ran across this script that will do just that.  I could not get it to run correctly running Vista or Windows 7, running Office 2007, or Office 2010, but was able to get it to run on XP with Office 2003.  Guess the MAPI calls are different or something.  If anyone knows how to make this work on Windows Vista/7, using Office 2007/2010 let me know!~

Here’s the script:

Public Const CdoDefaultFolderContacts = 5
snServername = wscript.arguments(0)
mbMailboxName = wscript.arguments(1)
set csCDOSession = CreateObject("MAPI.Session")
pfProfile = snServername & vbLf & mbMailboxName
csCDOSession.Logon "","",False,True,0,True, pfProfile
set cfContactsFolder = csCDOSession.getdefaultfolder(CdoDefaultFolderContacts)
set cfContactscol = cfContactsFolder.messages
set ofConFilter = cfContactscol.Filter
Set cfContFltFld1 = ofConFilter.Fields.Add("0x8015",vbBoolean,true,"0420060000000000C000000000000046")
For Each ctContact In cfContactscol
	Set collAttachments = ctContact.Attachments 
	For Each atAttachment In collAttachments
		If atAttachment.name = "ContactPicture.jpg" Then
			fname = replace(replace(replace(replace(replace((ctContact.subject & "-" & atAttachment.name),":","-"),"\",""),"/",""),"?",""),chr(34),"")
			fname = replace(replace(replace(replace(replace(replace(fname,"<",""),">",""),chr(11),""),"*",""),"|",""),"(","")
			fname = replace(replace(replace(fname,")",""),chr(12),""),chr(15),"")
			atAttachment.WriteToFile("c:\contactpictures\" & fname)
			wscript.echo "Exported Picture to : " &  fname
		End if		
	next
Next

Save the above code as a .vbs file, and run it from the command line:

exportOutlookPic.vbs mailboxservername exchangeAlias

Make sure that you have created the folder referenced in the script, or you will get an error (c:\contactpictures\).  Works like a charm!  I know have all my Outlook Contact pictures, in my folder system. 🙂





Save Hashed Password in RDP file

23 01 2009

Over on the main EverydayNerd.com website, I’ve posted an article about saving a hashed password in an .RDP file.  Hope you find it helpful!

http://everydaynerd.com/microsoft/save-password-in-rdp-file








Design a site like this with WordPress.com
Get started