Archive for category IT

PowerShell snips

An assortment of PowerShell scripts I have stumbled upon, modified where needed. Use at your own risk blah blah. :)
Sorry if I don’t give credit, but I simply can’t remember where I got them all from!
Many of them require Quest ActiveRoles Management Shell, an extension for Windows PowerShell (freeware).

Generic PowerShell

Read .CSV file and do something for each object:
ForEach ($usr in Get-Content “C:\temp\Users.csv”) { Get-Mailboxstatisti
cs($usr)}

Groups/AD users

Copy Group Members from Group A to B:
Get-QADGroupMember GroupA | % { Add-QADGroupMember GroupB -Member $_ }

Copy Group Membership information from User A to B:
(Get-QADUser userA).MemberOf | Add-QADGroupMember -Member domain\userB

“Bulk” change attributes on AD users:
Get-QADuser -sizelimit 0 | where-object { $_.Department -eq “Sales” } | foreach-object {Set-QADuser $_ -Department “Commercial”}
(Searches all users (sizelimit 0) where Department = “Sales” and for each object sets Department = “Commercial”)

Find “indirect” (nested) AD group memberships for a specific user:
Get-QADMemberOf “John Doe” -indirect | fl name,description >> C:\JDoe.txt

Find members of AD group, export to CSV:
get-qadgroupmember “group name” | select-object logonname, firstname, lastname | export-csv c:\filename.csv

Export selected ExtensionAttribute (or other) to CSV file

Get-QADUser -IncludedProperties extensionAttribute1 -sizeLimit 0 | Select-Object Name, samaccountname, extensionAttribute1 | Out-File C:\WhoIsWho.csv -width 400

Blank out ExtensionAttribute1 for all users that have it
Get-QADuser -sizelimit 0 | Set-QADUser -ObjectAttribute @{extensionAttribute1=$null}

Select users by country CAUTION, do not edit in this way!
Get-QADuser -sizelimit 0 -IncludedProperties c | Where-Object {$_.C -eq “GB” }

 

Exchange 2007/2010

Set Exchange mailbox quota:
set-mailbox “John Doe” -UseDatabaseQuotaDefaults $false -IssueWarningQuota 4GB -ProhibitSendQuota 5GB -ProhibitSendReceiveQuota 6GB
(Warning at 4GB, Block Send at 5GB and block receive at 6GB, remember to NOT use QuotaDefaults)

Export mailbox statistics to CSV file
C:\>Get-MailboxStatistics | ft Displayname,totalitemsize,databasename | Out-File C:\Mailboxstatistics.csv -width 200

Export mailboxes to .PST file
Add-mailboxpermission -identity “John Doe” -accessrights fullaccess -user “AdminUser01″
Export-Mailbox -Identity “John Doe” -PSTFolderpath X:\folder
(AdminUser01 has to be the one who’s running the Powershell at the moment of Exporting)

Removing disconnected mailboxes in Exchange Server 2007/2010
Listing all disconnected mailboxes:
Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid
Removing a single entry:
Remove-Mailbox -Database <Database-Name> -StoreMailboxIdentity <MailboxGuid> -confirm:$false
Removing all users at the same time:
$users = Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid
Now that we have all disconnected mailboxes in a var, we can run the following cmdlet to remove all of them:
$users | ForEach { Remove-Mailbox -Database “Mailbox Database” -StoreMailboxIdentity $_.MailboxGuid -confirm:$true }

 

Share

, ,

No Comments

Password Expiration Notice email

Found this very nice solution to sending password-reminders to users, all rights reserver Richard L. Mueller. http://www.rlmueller.net/PasswordExpires.htm

 

VBScript program demonstrating how to use ADO to find all user accounts where the password will expire within a specified number of days in the future. The program does not retrieve users whose password has already expired. The program also does not retrieve users whose password does not expire, whose password cannot change, where the user is not required to have a password, or where the account is disabled.

The program uses the domain maximum password age policy and the value of the pwdLastSet attribute of the users to determine when the passwords expire. Do not use this program if you use the new fine-grained password policies feature of Windows Server 2008. This program assumes the same password policy applies to all users.

The program filters on users where the pwdLastSet attribute corresponds to dates in the past such that the password will expire in the specified range. This requires converting the critical dates into the corresponding Integer8 values. For the users retrieved, the program uses the pwdLastSet attribute value to determine when the password will actually expire, in the time zone of the local computer.

For each user account found the program sends an email message to the user. The program uses the value of the “mail” attribute of the user object, which corresponds to the field “E-mail” on the “General” tab of ADUC. If this attribute does not have a value, the program uses the “proxyAddresses” attribute. This multi-valued attribute is used by Exchange to specify email addresses. This program uses the “primary” address of the user, which is the value which has either “SMTP:” or “X400:” as the prefix, in upper case. There can be only one “primary” email address in the collection. All other values have all lower case prefixes.

PwdExpires.txt <<– Click here to view or download the program

Next is a similar PowerShell script that retrieves all users whose passwords will expire within the specified number of days. An email function has recently been added, so the program is identical to the first.

PSPwdExpires.txt <<– Click here to view or download the program

 

Hosted copies of the original script can be found here:

PSPwdExpires.ps1

PwdExpires.vbs

 

I modified the script (PowerShell) to allow for HTML emails with multiple lines of text.

First bit:

Function SendEmail($To, $Body)
{
    $Message = New-Object System.Net.Mail.MailMessage `
        $Script:From, $To, $Script:Subject, $Body
	$Message.IsBodyHtml = "true"
    $Client.Send($Message)
}

Last bit (where you enter your custom text):

    If ("$Mail" -ne "")
    {
        $Notice = "<font size='2' face='Verdana'>" `
			+ "<b>This is an automated message!</b><br><br>" `
			+ "Your password for username $Name will expire by: <b>$PwdExpires</b> (mm/dd/yyyy) <br>" `
			+ "Before then you must change your password by following one of the procedures mentioned below: <br>" `
			+ "</font>"
        SendEmail $Mail $Notice
        "Email sent to $Name ($Mail), password expires $PwdExpires"
    }

 

 

 

 

 

 

 

Share

, ,

No Comments

Battlefield 3 CO-OP and playing with friends doesn’t work

Symptoms: When inviting a friend (in platoon or otherwise) to a game in Battlefield 3 on PC via the Battlelog (web-based) browser, one player will be unable to receive invites, and the invites that same player sends will not be usable by the other party. Also the player having this problem will not be able to receive chats, but can send.

Cause: Avast! Antivirus is causing this.

Solution: Disable Avast! Antivirus when playing Battlefield 3.

Confirmed with Avast! Program Version 6.0.1289, definitions version 111028-0

Share

, , , , , ,

1 Comment

VBScript: Bypass the “Open File – Security Warning” dialog from VbScript

Found this solution to an annoying VBscript problem that I just had to save here:

You have had it before: the “Open File – Security Warning”. Nice feature, but not very interesting during execution of scripts. However you may not want to turn it off.

The simple solution in VBScript has been offered by MS themselve: the SEE_MASK_NOZONECHECKS environment variable. Change it at the start of your script and restore it at the end. Plain & simple!

Sample code (same as the KB article):
set oShell= CreateObject(“Wscript.Shell”)
set oEnv = oShell.Environment(“PROCESS”)
oEnv(“SEE_MASK_NOZONECHECKS”) = 1
oShell.Run “c:\ms04-038\WindowsXP-KB834707-x86-enu /quiet /passive /norestart”,0,True
oEnv.Remove(“SEE_MASK_NOZONECHECKS”)

The Open File – Security Warning dialog box is displayed when you try to silently install a hotfix or an update by using a Visual Basic script in Windows XP Service Pack 2
http://support.microsoft.com/kb/889815

Share

No Comments

Exchange 2007 Certificate renewal

Reference/credits go to: http://telnetport25.wordpress.com/2008/07/13/windows-2008-exchange-2007-renewing-an-existing-ssl-certificate-on-your-client-access-server/

SSL certificates are issued for periods of spanning a number of years (typically in multiples for example 1, 2 or more years – however eventually they do expire and need to be renewed.

The renewal process involves generating a fresh CSR (Certificate Signing Request) on one of your Exchange Client Access servers – this is then sent to a root certification authority (for example VeriSign or Thwate) for processing into a valid SSL certificate (essentially they sign the request).

Read the rest of this entry »

Share

,

No Comments

Disable Image Resize Dialog in MS-Outlook

If you select an image file and choose “Send To — Mail Recipient” in the context menu, the Send Pictures via E-mail dialog appears to ask you if you want to resize the image. To disable the dialog and to directly open the email client with the image attachment, follow the instructions below. This tip was hard to find with Google, so I pasted it here verbatim:

To disable the resize dialog for .JPG file type, use these steps [Reference]:

  1. Click Start, Run. Type regedit.exe and press {ENTER}
  2. Navigate to the following location: HKEY_CLASSES_ROOT\.JPG
  3. Backup the key by exporting it to a file.
  4. In the right-pane, double-click PerceivedType and assign a blank data to it.
  5. Close Registry Editor.

The same procedure applies for other image types. The original source also gives this caution, however, I did not encounter the mentioned problem:

There may be some minor side effects of using this method, as the PerceivedType string is another important file class information. PerceivedType string helps Windows determine the actual Type (image, video, audio or whatever) for a file. In case you experience image preview issues or any other problems after following the method in this article, you can revert the setting by changing the PerceivedType to image. Alternately, type REGSVR32 SHIMGVW.DLL in Start, Run dialog to regain the functionality.

Share

,

No Comments

Logitech Flight System G940, my experiences

While working on my DIY simulator-seat (more on this when it’s done!), I decided I needed a ‘real’ joystick, with both stick and throttle (HOTAS – Hands On Throttle And Stick). I looked around and came up with 3 options; Logitech Flight System G940 (USD $300), Saitek X65-F Combat Control System (USD $400) or the Thrustmaster HOTAS WARTHOG (USD $500).

Not only was the Logitech the cheapest, it was also the only one that included Rudder pedals, as well as Force Feedback! Many people have complaints about the Logitech Gaming software – but having tried this previously with my G25 wheel, I wasn’t concerned. The Logitech G940 has one major drawback though; it shows up as 3 seperate input devices (Joystick, Throttle, Pedals) – and this can render it completely useless for some games.

The Saitek X65-F has ‘Force Sensing’ , which looks really awesome, but is apparently only really good for jet-fighter sims.
With both the Saitek X65-F and Thrustmaster HOTAS WARTHOG you will need separate pedals, further adding to the already high costs. (Saitek Pro Flight Combat Rudder Pedals $200, for the Thustmaster, CH Pro Pedals $123)

Read the rest of this entry »

Share

, , , ,

No Comments

Office 2007 problems after upgrading to Trend Micro Officescan 10.5

After upgrading from version 10.0 to 10.5 of Trend Micro’s Officescan antivirus client, we had problems opening all kinds of Office files (Word docs, Excel, Powerpoint etc.). We only observed it on Windows XP clients (fully updated otherwise) – but the client OS would freeze up and need a forced reboot.

The “solution” (until Trend fixes it) is to disable “Detect exploit code in OLE files” under Real-time Scan Settings. Force an update on the client and presto. ;-)

Share

, , ,

No Comments

XenServer on less than 16GB discs

Following this HowTo you are able to boot “Citrix XenServer 5.5 Upd 2″ on an HP 4GB SD-Card put into the internal slot of an HP DL380G6 server. This may also work using other hardware, even with other USB devices like disks or even sticks.
The key is, that normally install targets are only shown if they are a least 16Gb, because Citrix assumes that the local disk must also store some virtual machines. In SAN environments this is not necessary because XenServer itself only needs about 2Gb of storage. The other point is that the kernels initial Ramdisk needs driver support for the USB bootdevice

1. Prepare your Hardware to boot from USB

Setup your computers BIOS to boot from CD first, then USB. Maybe it’s wise to disable any other storage controllers.

2. Boot from XenServer installation CD

Wait until the Welcome-Screen and the “boot: ” prompt at the screen bottom appears. Then type “shell” and hit enter. This will prevent the installer from being startet automatically. After a while you end up in a Linux shell.

Read the rest of this entry »

Share

No Comments

Event ID 1041 after uninstalling Internet Explorer 8

Having removed Internet Explorer 8 from a Citrix Presentation Server farm, the following errors started appearing in the Application Log:

IE8 uninstall errors in App. Log (1)

IE8 uninstall errors in App. Log (1)

It shows up with 2 different messages, but with the same event ID:

IE8 uninstall errors in App. Log (2)

IE8 uninstall errors in App. Log (2)

.. and

IE8 uninstall errors in App. Log (3)

IE8 uninstall errors in App. Log (3)

This happens because IE8 doesn’t remove all traces when it uninstalls. There’s 2 leftover (empty) keys in the registry, and the errors then appear everytime a user is accessing IE7.

The keys to delete are:

7B849a69-220F-451E-B3FE-2CB811AF94AE

CF7639F3-ABA2-41DB-97F2-81E2C5DBFC5D

And they are both found in:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions\

Apparently this error has been present since IE8 beta, and it still hasn’t been fixed by Microsoft. Shame on you.

No restart needed.

Share

1 Comment