Category Archives: Code

Any Coding or Hacks to perform a task

Exchange 2010 | OWA Blank page (“HTTP 500” error)

Scenario: OWA web address shows login prompt and the user is able to logon, but a blank page or “HTTP 500” error displays once logged in. The page may also be blank depending on browser settings and if “show friendly URLs” is selected.

Even after a “IISReset /NoForce” or Server reboot, the problem is not fixed.

Cause: Looks like this problem is related to the “Microsoft Exchange Forms-Based Authentifcation Service” not being started or failed to start. This service can just be started from “services.msc”

net start MSExchangeFBA

Note: a number of posts state this problem is related to not having the”RPC over HTTP Proxy” role installed. However in my case the server had been working successfully.

If you have a new migration or build of Exchange 2010 then you may need to ensure that all required features are installed on the exchange server:

Open "Powershell" run as administrator<br />
Import-Module ServerManager<br />
Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -Restart<br />

 

Show Host Name via VBS (ShowHost.vbs)

Simple script to show host name of the local machine in a popup window add code to “ShowHost.vbs”

Dim Shell
Dim CompName
Set Shell = WScript.CreateObject("WScript.Shell")
CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Msgbox "Your Computer name is " &amp; CompName

Logmein – Disconnect Remote Printer (regedit)

When using Logmein the local printer is automatically redirect to the server/pc by default. This can be turned off by either deleting the printer from “devices & printers” or unticking the printer on the logmein icon bar. Unfortunately the printer will simply reattached itself when you logoff / logon again. In order to stop printer redirection permanently you will need to update the use this regedit (this was confirmed by logmein support 2011/12/22)

I was experiencing the problem with users of a terminal server remotely printing to my PC by default while I was “admining” the server.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\LogMeIn\V5\RemoteControl]
"EnableRemotePrinting"=dword:00000000

Locating MAC addresses (Local & Remotely)

Finding out MAC address using ping and IP address

  • cmd -> ping 1.2.3.4
  • After some echo replies from host 1.2.3.4
  • cmd -> arp -a
  • MAC address of will be displayed

Finding out MAC address using NBTSTAT and machine name.

  • cmd ->nbtstat -a machinename
  • MAC address of will be displayed

Finding out MAC on local host

  • cmd -> getmac
  • MAC address of will be displayed

Create a CustomPowerSave using PowerCFG (*.BAT)

This set of commands will create a new powersaving mode in XP with the name “CustomPowerSave” and set it as default. This has not been tested in Windows 7. You can drop this code below into a “CustomPowerSave.bat” file and run. This will also need some tweaking and testing to get working correctly.


POWERCFG /CREATE CustomPowerSave
POWERCFG /CHANGE CustomPowerSave /monitor-timeout-ac 5
POWERCFG /CHANGE CustomPowerSave /disk-timeout-ac 10
POWERCFG /CHANGE CustomPowerSave /standby-timeout-ac 20
POWERCFG /CHANGE CustomPowerSave /hibernate-timeout-ac 0

POWERCFG /GLOBALPOWERFLAG off /OPTION RESUMEPASSWORD
POWERCFG /SETACTIVE CustomPowerSave

Get switch options using:
cmd -> powercfg /?

Popup Test

I was using this to test GPOs were run at user login. if the popup displayed then i knew the object had been executed.

bat: START CMD /C "ECHO Popup Test && PAUSE"

exe: popup-test.exe

vbs (will call and execute the exe from the specified location):

Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "%userprofile%\desktop\popup-test.exe", 6, True
set wshshell = nothing

BACKUP!

DO A STANDALONE BACKUP NOW!

This is something we all overlook and it makes life so much easier if you have a copy just dumped to a network share!

GPO Backup:

GPO Restore:

DHCP Backup:

 

Forward mail to a Public Folder | EMC PowerShell

This will forward mail to the public folder

Set-Mailbox "NAME.SURNAME" -ForwardingAddress "email@domain.com"
Set-Mailbox "NAME.SURNAME" -ForwardingAddress "email@domain.com" -DeliverToMailboxAndForward $true

Source: Exchangepedia how to forward mail to a public folder.

Bridgehead Servers, Intersite Links and RepAdmin

Bridgehead Servers

A bridgehead server is a domain controller in each site, which is used as a contact point to receive and replicate data between sites. For inter-site replication, KCC designates one of the domain controllers as a bridgehead server. In case the server is down, KCC designates another one from the domain controller. When a bridgehead server receives replication updates from another site, it replicates the data to the other domain controllers within its site.

Repadmin Sync: (Synchronizes DC with replication partners)

repadmin /syncall

Bridgehead Servers: (Displays bridgehead servers)

repadmin /bridgeheads

Troubleshooting:

Seeing a number of KCC replication errors in the event log, no doubt there is something not configured correctly in “Site-&-Services”  This Microsoft document should give you a few tips. Troubleshoot with Repadmin

Continue reading

Querying FSMO roles & ADPREP

To find out what domain controller roles are within the organisation:

List all DCs in forest with DN and RDN:

DsQuery Server -o rdn -Forest
DsQuery Server -Forest

List all the DCs in domain:

DsQuery Server -domain domain_name.com

List all the DCs in domain (that are Global Catalog Servers):

DsQuery Server -domain domain_name.com -isgc

List all DCs in forest (that hold FSMO):

DsQuery Server -Forest -hasfsmo schema

Use the “>” to store the output to a text file. The below command will store all the domain controller names in AllDCs.txt.

DsQuery Server -Forest &gt; AllDCs.txt

List FSMO roles using NETDOM

netdom query fsmo

Adding a new Domain Controller to the Domain.

ADPREP commands to upgrade Domain Controllers (In this order)

ADPREP /forestprep
ADPREP /domainprep
ADPREP /domainprep /gpprep
ADPREP /rodcprep
Guide to Windows Server 2008 ADPREP: 
Problems with ADPREP and SYSVOL migration process:

How to view and transfer FSMO roles in Windows Server 2003
http://support.microsoft.com/kb/324801

How do I install Active Directory on my Windows Server 2003 server?
http://www.petri.co.il/how_to_install_active_directory_on_windows_2003.htm

DNS Zone export to TXT & Clear DNS

Exports the contents of the specific DNS zone to a .txt file. Just makes the process easier for debugging etc, when dealing with larger DNS zones:

dnscmd /zoneexport domain.com c:\zones-export.txt

Clears the local computer cache.

Ipconfig /flushdns

Clears the DNS server cache.

dnscmd /clearcache

Exchange *.Log File Removal (BAT)

It is BAD BAD practice to try and delete the exchange 2007 log files! It should not be done ever!

Running into space issues on exchange needed to remove 80,000+ *.log files. These would be removed by doing a backup, but without any space to run the backup there’s not a lot of options.

I ran this command to perform a removal of the log files in the mailbox DB, I had to use this script the job as the windows would crash as soon as multiple files were highlighted and selected for deletion:

  • CD /D E:\Exchange\Mailbox\First Storage Group
  • del /s *.txt

In order to move logs onto another drive use this command:

  • CD /D E:\Exchange\Mailbox\First Storage Group
  • move *.log “K:\Exchange_Logs_Move”

DO NOT DELETE / REMOVE THFOLLOWING FILES:

  • E00.chk
  • E00.log
  • Mailbox Database.edb

Add Network Printer via VBS

Use the script below to add a network printer, you can simply dump this into a txt file, rename to a .VBS and change the printer addresses (these need to be shared of course!)
The last bit of code should stop the “Error: 8007007B – the filename, directory name, or volume label syntax is incorrect” as it will keep retrying the connection to the printer share if the network is slow and timming out etc.

Last bit is to drop the script into the DC netlogon and add to group policy! BAMM!


Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\server\printer"
net.SetDefaultPrinter "\\server\printer"

MapPrinter "\\server\printer"

Sub MapPrinter(strPrinter)
On Error Resume Next
Set objNetwork = CreateObject("WScript.Network")
boolConnected = False
intAttempts = 1
While boolConnected = False And intAttempts <= 5
Err.Clear
objNetwork.AddWindowsPrinterConnection strPrinter
If Err.Number <> 0 Then
intAttempts = intAttempts + 1
WScript.Sleep 2000
Else
boolConnected = True
End If
Wend
End Sub

“Active Desktop Recovery” / Script Error

“Active Desktop Recovery”

“An error has occurred in a script on this page”

Not 100% sure why this error occurs, however if you bung this information into a VBS file and run “hey-presto” the error is gone and the background is back to normal. I have only seen this when there is a GP in place that sets the background and doesn’t allow it to be changed by the user, I think this could be why it can’t just be changed back!

Most other fixes I’ve tried mean you have to reset the computer or uninstall/reinstall Internet Explorer (IE), I must have wasted hours on this problem until I found this script!

Option Explicit
' Create the Shell object
Dim objShell
Set objShell = CreateObject("WScript.Shell")
'Change values that mess up IE 7 from decimal 272 to 0
objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\Desktop\SafeMode\Components\DeskHtmlVersion", "0",
"REG_DWORD"
objShell.AppActivate "Program Manager"
objShell.SendKeys "{F5}"
WScript.Quit

RDP via TS Web “error occurred… Desktop Gateway server.”

Problem connecting to server via RDP when using the TS web interface.

  1. Login OK to the TS Web Interface.
  2. Click “Connect” to server
  3. RDP Loads…
  4. Error displays: “An error occurred while sending data to the Remote Desktop Gateway server. The server is temporarily unavailable or a network connection is down. Try again later, or contact your network administrator for assistance.”

Note: This problem is related to newer features in RDP v7 which are not installed by default on Windows XP Service Pack 3 (SP3), Windows Vista Service Pack 1 (SP1), and Windows Vista Service Pack 2 (SP2)

Fix:

Turn on CredSSP.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
Right-click -> Security Packages -> Modify -> type “tspkg”. (Leave other info) -> click OK.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders

Right-click -> SecurityProviders -> Modify -> type “credssp.dll” (Leave other info) -> click OK.

Exit -> Restart computer

Outlook 2007 | Cached Mode

In order to change outlook to allow cached exchange mode for multiple mailboxes change the following reg key:

Key: HKCU\Software\Microsoft\Office\12.0\Outlook\Cached Mode
DWORD: CacheOthersMail
Value: 1

Close Outlook, after you have changed / added this key start Outlook.
When you access the shared mailboxes – the first time it will download the content then after this access will be much faster – same as your main mailbox

Note: this fix is also in Office SP2 so best off just updating the SP.

BCDEdit – VHD into boot.ini

bcdedit /copy {current} /d “XPP32-VHD”
bcdedit /set {ef3e950f-0d1f-11df-81c3-0009dd502a5a} device vhd=3D[J:]\Virtual_PC\Microsoft-VPC\Windows-XPP32\Windows-XPP_HDD_10gb_Office2003_DYN.vhd
bcdedit /set {ef3e950f-0d1f-11df-81c3-0009dd502a5a} osdevice vhd=3D[J:]\Virtual_PC\Microsoft-VPC\Windows-XPP32\Windows-XPP_HDD_10gb_Office2003_DYN.vhd
bcdedit /set {ef3e950f-0d1f-11df-81c3-0009dd502a5a} detecthal on
bcdedit /delete {6a8b1f82-071e-11df-8287-c6f21c814b9c} /cleanup
bcdedit /delete {ef3e950e-0d1f-11df-81c3-0009dd502a5a} /cleanup

Ref: Windows 7 to VHD
 

Adding Printer via Net Use LPT

Command Line:

NET USE LPT1: \\server\printername /persistent:yes

If this error occurs: “System error 85 – device name already in use” – Meaning the LPT port has already been mapped.

Check what LPT is in use:

NET USE

Change LPT1 to LPT2

TS Web Access not working – ActiveX not installed or enabled

Microsoft RDP ActiveX Control is disabled when you install Windows XP Service Pack 3 or Windows Small Business Server 2003 SP1.

Use the Manage Add-ons dialog in Internet Explorer to enable the Terminal Services ActiveX Control, if the ActiveX control is not listed in Manage Add-ons dialog deleting the following registry keys:

Option1:

HKCU\Software\Microsoft\Windows\CurrentVersion\Ext\Settings\{7390f3d8-0439-4c05-91e3-cf5cb290c3d0}
HKCU\Software\Microsoft\Windows\CurrentVersion\Ext\Settings\{4eb89ff4-7f78-4a0f-8b8d-2bf02e94e4b2}

Option2:

run -> cmd.exe /C “cscript %systemroot%\Installer\TSClientMsiTrans\tscuinst.vbs”

Once you delete these keys, the activeX control should be enabled.