Mittwoch, 30. Dezember 2009

Get the Service Tag from Dell computers

Get-WmiObject win32_SystemEnclosure | select serialnumber

WSUS automated Cleanup

This script performs the cleanup tasks done by the WSUS cleanup wizard. Because it is a script, it can be automated (for example, via the Windows Task Scheduler). It also provides extended support for computer cleanup, allowing one to specify the number of days of not hearing from the computer before cleanup (default is 30 days), and to optionally skip deletion of computers that are still in Active Directory Directory Services (to avoid accidently removing computers that are still around but having trouble contacting the server). We recommend also performing SQL defragmentation sample script as part of WSUS cleanup.
Thx to ScriptingGuys.

[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")`
| out-null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope;
$cleanupScope.DeclineSupersededUpdates = $true
$cleanupScope.DeclineExpiredUpdates = $true
$cleanupScope.CleanupObsoleteUpdates = $true
$cleanupScope.CompressUpdates = $true
#$cleanupScope.CleanupObsoleteComputers = $true
$cleanupScope.CleanupUnneededContentFiles = $true
$cleanupManager = $wsus.GetCleanupManager();
$cleanupManager.PerformCleanup($cleanupScope);

Exchange Autodiscover Song

You have to hear the Autodiscover Song :)

http://tinyurl.com/ylyrr6n

Lyrics:


Autodiscover

There is no other
Way to decide
Where your mailbox is stored


Autodiscover
Your sister and brother
Exchange Admin and mother
Will be proud if you do

You may be tempted to wing it
Use a hardcoded link submit it
But performance will suffer
When you’re left to your druthers
Should have Autodiscovered
Then all would be well


Chorus
Call it once for each mailbox of interest
Pair the link and mailbox for each request
If you encounter errors
Refresh once again
For more information search M-S-D-N for

Chorus

Exchange won't exist in a bubble
If you think that it will you're in trouble
Add a site, one or two
And your perf will be through
Unless you step up and decide that your app will just...

Chorus

Autodiscover,
Autodiscover,
Just AutoDiscover for me.
It’s just plain XML

Montag, 28. Dezember 2009

ISA Server 2006 - PPTP / RRAS Probleme mit Update KB956570

How to disable this update
If you encounter problems after you install this update, you can disable this update.

At the command prompt, type the following command:
cscript KB956570.vbs
Restart the computer that is running ISA Server.

----------------------------------------------------------------------------

Const SE_VPS_GUID = "{143F5698-103B-12D4-FF34-1F34767DEabc}"
Const SE_VPS_NAME = "BindRandomizationCount"
Const SE_VPS_VALUE = 0

Sub SetValue()

' Create the root object.
Dim root ' The FPCLib.FPC root object
Set root = CreateObject("FPC.Root")

'Declare the other objects needed.
Dim array ' An FPCArray object
Dim VendorSets ' An FPCVendorParametersSets collection
Dim VendorSet ' An FPCVendorParametersSet object

' Get references to the array object
' and the network rules collection.
Set array = root.GetContainingArray
Set VendorSets = array.VendorParametersSets

On Error Resume Next
Set VendorSet = VendorSets.Item( SE_VPS_GUID )

If Err.Number <> 0 Then
Err.Clear

' Add the item
Set VendorSet = VendorSets.Add( SE_VPS_GUID )
CheckError
WScript.Echo "New VendorSet added... " & VendorSet.Name

Else
WScript.Echo "Existing VendorSet found... value- " & VendorSet.Value(SE_VPS_NAME)
End If

if VendorSet.Value(SE_VPS_NAME) <> SE_VPS_VALUE Then

Err.Clear
VendorSet.Value(SE_VPS_NAME) = SE_VPS_VALUE

If Err.Number <> 0 Then
CheckError
Else
VendorSets.Save false, true
CheckError

If Err.Number = 0 Then
WScript.Echo "Done with " & SE_VPS_NAME & ", saved!"
End If
End If
Else
WScript.Echo "Done with " & SE_VPS_NAME & ", no change!"
End If

End Sub

Sub CheckError()

If Err.Number <> 0 Then
WScript.Echo "An error occurred: 0x" & Hex(Err.Number) & " " & Err.Description
Err.Clear
End If

End Sub

SetValue

Samstag, 26. Dezember 2009

Add Feature Microsoft .NET Framework 3.5. during Exchange 2010 Install

While installing Exchange 2010, you may get the following error message:

"You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5."

Cause Windows 2008 R2 ships with .Net 3.5.1, you just need to enable the feature within the Server Manager -> Features:

Service Net. TCP Port Sharing / Exchange 2010




During the Readiness Checks you get the following error:

The start mode for the Net. TCP Port Sharing service must be set to Automatic before Setup can continue”.

Open Powershell:

Set-Service NetTcpPortSharing -StartupType Automatic

Samstag, 19. Dezember 2009

Get the Names of Mailboxes That are Quota+

get-MailboxStatistics | where {"IssueWarning","ProhibitSend","MailboxDisabled" -contains $_.StorageLimitStatus} | format-Table DisplayName,TotalItemSize

ISA 2006 Backup Script

' based on: http://www.it-training-grote.de/download/isabackup/backup.htm

' Usage: cscript /nologo ISABackup.vbs strBackupShare

' - strBackupShare (String) UNC Path of the Share where the Backup will be stored


' Should the Script send any notification E-Mails
Const blSendMails = true

' The E-Mail Server to use when sending Backup notifications
Const strEmailServer = server.local"

' The E-Mail Address from which the Mails will appear to come from
Const strEmailFromAddr = "postmaster@domain.tld"

' The Recipients od the Backup notifications. Multiple Recipients are to be separated with a semicolon.
Const strEmailRecipients = "info@domain.tld"

Private Sub SendEmail (ByVal strFrom, strRecipient, strSubject, strText, strServer, isUrgent)

Dim objEmail

Set objEmail = CreateObject("CDO.Message")

objEmail.From = strFrom
objEmail.To = strRecipient
objEmail.Subject = strSubject
objEmail.Textbody = strText

If isUrgent Then

With objEmail.Fields

.Item("urn:schemas:mailheader:X-MSMail-Priority") = "High"
.Item("urn:schemas:mailheader:X-Priority") = 2
.Item("urn:schemas:httpmail:importance") = 2
.Update

End With

End If

With objEmail.Configuration.Fields

.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update

End With

objEmail.Send

End Sub

Function LogConsoleOutput (ByVal strText)

strText = GetTimeString & ": " & strText

objEventLogFile.WriteLine strText

strConsoleOutput = strConsoleOutput & strText & vbCrLf

WScript.echo strText

End Function

Function AppendZeroToTen (byVal Input)

If (Input < 10) Then
AppendZeroToTen = "0" & Input
Else
AppendZeroToTen = Input
End If

End Function

Function GetDateString

Dim dtmCurrentDate, dtmDay, dtmMonth, dtmYear

dtmCurrentDate = date()

dtmDay = DatePart("d", dtmCurrentDate)
dtmMonth = DatePart("m", dtmCurrentDate)
dtmYear = DatePart("yyyy", dtmCurrentDate)

GetDateString = AppendZeroToTen(dtmDay) & "." &_
AppendZeroToTen(dtmMonth) & "." &_
AppendZeroToTen(dtmYear)

End Function

Function GetTimeString

Dim dtmCurrentTime, dtmHour, dtmMinute, dtmSecond

dtmCurrentTime = time()

dtmHour = DatePart("h", dtmCurrentTime)
dtmMinute = DatePart("n", dtmCurrentTime)
dtmSecond = DatePart("s", dtmCurrentTime)

GetTimeString = AppendZeroToTen(dtmHour) & ":" &_
AppendZeroToTen(dtmMinute) & ":" &_
AppendZeroToTen(dtmSecond)

End Function

Function DeleteIfExists (byVal strFile)

if objFSO.FileExists(strFile) Then

objFSO.DeleteFile(strFile)

End If

End Function

Dim objFSO : set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objNetWork : set objNetWork = CreateObject("WScript.Network")
Dim strBackupShare : strBackupShare = WScript.Arguments(0)
Dim objXMLDOM : set objXMLDOM = CreateObject("Msxml2.DOMDocument")
Dim objFPC : set objFPC = WScript.CreateObject("fpc.Root")
Dim objISAArray : set objISAArray = objFPC.GetContainingArray
Dim strFileName
Dim blErrorsOccurred : blErrorsOccurred = false
Dim strHostName : strHostName = objNetWork.ComputerName
Dim strEmailSubject : strEmailSubject = strHostName & ": Backup am " & GetDateString & " durchgeführt"
Dim strConsoleOutput


strScriptPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
strEventLogFile = strScriptPath & "logs\" & strHostName & "-D" & Replace(GetDateString,".","") & "-T" & Replace(GetTimeString,":","") & ".txt"

DeleteIfExists (strEventLogFile)
set objEventLogFile = objFSO.CreateTextFile(strEventLogFile, CopyOverwrite)

LogConsoleOutput "Starting Backup"
LogConsoleOutput "Logging to Text File " & strEventLogFile

strFileName = strBackupShare & "\" & strHostName & "-D" & Replace(GetDateString,".","") & "-T" & Replace(GetTimeString,":","") & ".xml"

LogConsoleOutput "Exporting Configuration"

objISAArray.Export objXMLDOM, 0

LogConsoleOutput "Saving exported Configuration to File " & strFileName

objXMLDOM.save(strFileName)

LogConsoleOutput "Backup Finished"

If blSendMails Then

Call SendEmail (strEmailFromAddr, strEmailRecipients, strEmailSubject, strConsoleOutput, strEmailServer, blErrorsOccurred)

End If

objEventLogFile.Close

Mittwoch, 16. Dezember 2009

Delete Files older then X Days Powershell

1. set-executionpolicy RemoteSigned
2. within a batch -> powershell -command "& 'SCRIPTNAME.ps1' " for Scheduled Task.



Function GetOldFile
{
$Days = "2"
$TargetFolder = "C:\pathtofolder"
if (Test-Path $TargetFolder)
{
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.log -recurse |Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{write-host "Deleting file $File" -foregroundcolor "Red"; Remove-Item $File | out-null}
}
Else
{Write-Host "Folder $TargetFolder doesnt exist! Recheck the folder path!"}
}
GetOldFile

Saved Queries to Query Locked Out Accounts

You can use the Saved Queries feature of Windows Server 2003 to query Active Directory for any locked-out accounts. Just open the Active Directory Users and Computers console, right-click on Saved Queries in the console tree and select New --> Query. Type a name and description for the query, specify a query root (where in your namespace your query begins searching), and click the Define Query button. Since there's no default option for finding locked-out accounts in the Common Queries box, select Custom Search instead to open the Find Custom Search box. Then select the Advanced tab and enter the following LDAP string in the Enter LDAP Query textbox:

(&(&(&(objectCategory=person)(objectClass=user)(lockoutTime:1.2.840.113556.1.4.804:=4294967295))))

Click OK twice to create and run the saved query.
The string works on Windows Server 2003 SP1.
Update: Here's another LDAP query that finds all locked out accounts:

(&(objectCategory=Person)(objectClass=User)(lockoutTime>=1))

Dienstag, 15. Dezember 2009

Restart mgmt-vmware ESX 3.x

How to restart mgmt-vmware on a VMware ESX 3.x:

SSH to the Vmware ESX

sudo-

service mgmt-vmware restart

or /sbin/service mgmt-vmware restart

This would be the solution if you can’t connect to the box using VMware Infrastructure Client, like if you get an error saying:
Error Connecting
VMware Infrastructure Client could not establish the initial connection with the server ““.
Details: The server took too long to respond.