Monday, May 31, 2010

WinZip: Network ZIP file locking issue

Issue: Trying to delete WinZip files from a network share can sometimes cause an error:"Error Deleting File or Folder - Cannot Delete [filename]: It is being used by another person or program."

Steps tried to resolve issue:
Determined issue is on multiple computers and under different user accounts.
Determinied issue is only if WinZip is installed and associated with zip files.
"Unlocker" says there is no program locking the zip file, when it says "file in use". In some cases it says explorer.exe is the culprit.
Determined that long path name was not the issue.
Removed Antivirus and the issue still occured.
Tried to delete using both UNC and drive name - same issue.
Tried using shares on other servers - same issue.

In the end, used Sysinternals Process Monitor to determine if there were any locks - which I couldn't find any. I then used Process Explorer to see what processes were running. Because I knew Explorer.exe was the process that locked it (unlocker had returned this a couple of times), I had a browse through the handles under Explorer.exe process. One such process was WZSHLSTB.DLL. I went through the registry and found the shell extension location under the following location:

[HKEY_CLASSES_ROOT\CLSID\{E0D79305-84BE-11CE-9641-444553540000}\InProcServer32]@="C:\\PROGRA~1\\WINZIP\\WZSHLSTB.DLL"

After deleting this key, the WinZip context menu disappeared, but the issue also disappeared. This led me to believe that WinZip must be the culprit. I went through the WinZip Configuration settings to see what might cause a lock on the file on network drives.

Solution:
And this is where I found the solution...

A couple of options caused WinZip to do some analysis of associated zip files when the mouse hovered over the file, or the file was right clicked to display the context menu. These options are:

Configuration --> Explorer Enhancements --> Display comment tool tips for Zip files: On other drives (eg. network drives)
Configuration --> Explorer Enhancements --> Check for self-extracting CAB files: On other drives (eg. network drives)

After turning off the first of these configuration items, the issue did not reappear.

Thursday, May 27, 2010

Excel 2007: Date formats

Ever tried copying dates into Excel, to have Excel refuse to format them as a date?

If you press F2 on the cell containing the date and press enter, it may then update to the format, but what if you have a 1000 dates to update?

Well, you could always record a Macro that does ActiveCell.Value = ActiveCell.Value and then moves to the next line to do the same thing. However there is a "bug" with this. Excel VBA will always interpret dates as a US format, unless it encounters a date that cannot be US e.g. 25/12/2005, in which case it will interpret it as dd/mm/yyyy. Ouch!

Solution:
1. Set an empty cell to the date format that you require.
2. Set the cells containing the dates to the date format that you require.
3. Copy the empty cell, and "Paste Special" over the cells containing dates. Select "All" and "Add" then click OK.

Thursday, May 20, 2010

Excel: Grabbing primary SMTP address from an Exchange 5.5 export

This is an Excel function that allowed me to grab the primary SMTP address from an Exchange 5.5 export of users: -

=IF(ISERROR(MID(R18,FIND("SMTP",R18)+5,FIND("%",R18,FIND("SMTP",R18)+5)-FIND("SMTP",R18)-5)), RIGHT(R18,LEN(R18)-FIND("SMTP",R18)-5), MID(R18,FIND("SMTP",R18)+5,FIND("%",R18,FIND("SMTP",R18)+5)-FIND("SMTP",R18)-5))

Exchange 2007: Remove and add public folder permissions recursively

When adding permissions to public folders in Exchange 2007, if one of the permissions to be assigned already exists, it will throw an error and not work. To work around this, you can remove the permissions for the user and then add back in the correct permissions.

a) Remove permissions recursively for anonymous

get-publicfolder \PublicFolder1\Airport -recurse | Get-PublicFolderClientPermission -user anonymous | remove-publicfolderclientpermission -confirm:$false


b) Remove permissions recursively for default

get-publicfolder \PublicFolder1\Airport -recurse | Get-PublicFolderClientPermission -user default | remove-publicfolderclientpermission -confirm:$false


c) Add permissions recursively for default

get-publicfolder \PublicFolder1\Airport -recurse | add-publicfolderclientpermission -user Default -AccessRight PublishingEditor

Exchange 2007: Report on Exchange statistics in Exchange 2007

a)
Get-MailboxServer | where {$._Name -Like "*EX*"} | Get-Mailbox | export-csv -Path C:\Mailboxes.csv

b)
Get-MailboxServer | where {$._Name -Like "*EX*"} | Get-Mailbox | Get-User | export-csv -Path C:\MailboxADProperties.csv

c)
Get-MailboxServer | where {$_.Name -Like "*EX*"} | get-mailboxstatistics | export-csv -Path C:\Mailboxstat.csv

Use Excel to match up the results of a) and b) and c).

There is apparently a way to do all this matchup in Powershell but I haven't looked into these options yet. One such suggestion on a forum was:

Get-Mailbox MBXName | Select-Object name,primarysmtpaddress, DisplayName,Database,@{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{n="Items"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount}}

Friday, May 14, 2010

Exchange: Check if email addresses are or are not on a mailbox in Exchange 2007

These scripts check whether a mailbox does or does not contain an email address. This is a great way to find out which mailbox in an organisation contains a certain email address.

Check if an email address is on a mailbox:

get-mailbox | where {$_.EmailAddresses -like "*@emailaddress.com"}

Check if an email address is NOT on a mailbox:
get-mailbox | where {-not ($_.EmailAddresses -like "*@emailaddress.com")}

Another way to check that an email address is not on a mailbox is to cycle through the EmailAddresses array:
Get-Mailbox | foreach {
For ($i=0;$i –lt $_.EmailAddresses.Count;$i++)
{
$address = $_.EmailAddresses[$i]
If($address.SmtpAddress –like "*@test.com")
{
Write-Host $_.Name
Break
}
}
}

Tuesday, May 11, 2010

ADMT: Configuring source and target domains for ADMT

This document deals with the prerequisites for configuring ADMT to migrate between two domains.

For this example, DOMAINA is the source domain. DOMAINB is the target domain.

When performing these steps in a production environment you should ensure that your networks are routable and firewall requirements have been met.

DOMAINB: Install ADMT
1. Install ADMT on a Windows Server 2008 server in the target domain
2. Configure the ADMT database to a central SQL Server in order for it to be backed up
3. Ensure the ADMT database is backed up
4. Ensure the ADMT server is backed up if possible

DOMAINA: Create ADMT Migrator account
1. Create ADMT Migrator account
2. Add ADMT Migrator account to DOMAINA\Domain Admins group
3. Ensure ADMT Migrator account is enabled

DOMAINB: Configure ADMT Migrator account
1. Add ADMT Migrator account to DOMAINB\Administrators group
2. Add ADMT Migrator account to ADMT Server local Administrators group
3. Add ADMT Migrator account to ADMT_Migrator, Account Migrator, Resource Migrator and Data Reader on the ADMT SQL database

DOMAINA: Source domain prerequisites
1. Do not create the DOMAINA$$$ group as ADMT sometimes does not like this group to be pre-created. ADMT will create this group automatically
2. Modify the registry on DOMAINA PDC Emulator
a. Browse to HKLM\SYSTEM\CurrentControlSet\Control\LSA
b. Add new DWORD value: TcpipClientSupport and set it to value: 1
3. Configure Audit Account Management
a. Open the Default Domain Controllers group policy
b. Browse to Computer ConfigurationàWindows SettingsàSecurity SettingsàLocal PoliciesàAudit Policy
Select Audit Account Management and enable for both Success and Failure
Click OK and close the Group Policy
Run gpupdate /force on all domain controllers in DOMAINA
Run rsop.msc on each domain controller in DOMAINA and confirm that the setting has applied successfully

DOMAINB: Destination domain prerequisites
4. Configure Audit Account Management
g. Open the Default Domain Controllers group policy
h. Browse to Computer ConfigurationàWindows SettingsàSecurity SettingsàLocal PoliciesàAudit Policy
Select Audit Account Management and enable for both Success and Failure
Click OK and close the Group Policy
Run gpupdate /force on all domain controllers in DOMAINB
Run rsop.msc on each domain controller in DOMAINB and confirm that the setting has applied successfully

DOMAINB: Configure PES (Password Encryption Service)
1. Create a user account to act as the PES service account called DOMAINA\SVC_PES
2. Generate PES encryption key on ADMT migration server
3. Log into the ADMT server
4. Run admt key /option:create /sourcedomain:DOMAINA /keyfile:c:\Folder /keypassword [Password ]
5. [Password] – Decide on a password to enter here and write it down – this password will need to be entered when importing the encryption key.

DOMAINA: Configure PES (Password Encryption Service)
1. Copy the encryption file to the PDC Emulator in the DOMAINA domain
2. Deploy PES on the PDC in DOMAINA domain:
Download pwdmig.msi to the PDC Emulator in DOMAINA domain
Execute pwdmig.msi
Click Next, accept the license agreement, click next
Browse for the encryption file and click next
Specify the password that was set on the file earlier
Specify the account to run the PES service under – this will be DOMAINA\SVC_PES
i. Use the password provided
Restart the PDC emulator to activate the PES and registry changes
Create 3 test users in NDS and have them replicate to DOMAINA
Create 3 test groups in DOMAINA and add the replicated test accounts to the 3 groups, which will be for testing the ADMT migration process

DOMAINB: Perform test migration using ADMT
Perform migration of a test group from DOMAINA to DOMAINB using ADMT and ensure successful migration of SID History
Make sure to log into migration server as the migration user DOMAINA\ADMT_migrator
Perform migration of the selected group using ADMT
Check the logs to see that SID history was successfully migrated
Check the migrated user account in ADSIEdit.msc to ensure SIDHistory is attached
Test for successful end to end migration by migrating a test account from DOMAINA to DOMAINB and merging the corresponding eDirectory accounts using an NDS Migrator console, and testing for group membership, password migration, SID History migration and access to resources as applicable

Monday, May 10, 2010

Scripting: Adding DNS Servers to a network connection

Netsh is used to add DNS servers to a network interface. To set the primary DNS server, run the command:

netsh interface ip set dnsserver "Local Area Connection" static 1.2.3.4

This only works for primary DNS servers however. To add additional DNS servers, enter the following command:


netsh interface ip add dnsserver "Local Area Connection" 1.2.3.7

Of course then you might like to register the connection in DNS with the following command:
ipconfig /registerdns

Wednesday, May 5, 2010

Scripting: Batch files - how to do stuff

Batch files generally start with:

@echo off
cls

If you want to call a batch file within another batch file:

CALL .\folder\batchfile.cmd

If you want to set a variable:

SET VARIABLENAME=value

To use an IF loop to check if a variable is right:

IF %MODE%==ALL (
Echo Your mode is set to copy inital data, montie, and user folders
CALL .\Scripts\InitialDataCopy.cmd
CALL .\Scripts\InitialUserCopy.cmd
GOTO END
)

To check if a file exists:

IF EXIST %TEXTFILE_BASE%\%TEXTFILE_NAME% GOTO READFILE

To read in values from a CSV file and echo them to screen:

For /F "tokens=1-3 delims=,. " %%a in (%VAR_CONTAINING_FILENAME%) Do (
echo %%a, %%b, %%c
)

Tokens: 1-3 means it will read up to three variables on each line, each assigned as %%a, %%b, and %%c.
delims: the delimiter between each variable. For a CSV file this will be the comma ",".