Monday, February 18, 2013

'VBScript to check file creation date and extension name 
'Script checks for files with particular extension in the specified folder and checks their creation date
'Rahul Patel

option explicit

dim objFSO, objStartFolder, objFolder, colFiles, ObjFile, DFC, count, objMessage
Set objFSO = CreateObject("Scripting.FilesystemObject")

'Change the directory you want to check for the file generation
objStartFolder = "C:\Temp"

Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.path

Set colFiles = objFolder.Files
Set objMessage = CreateObject("CDO.Message")

count = 0

For Each objFile in colFiles
'the FileExtension is CASE SENSITIVE... so make sure the extension check has the correct CASE
If objFSO.GetExtensionName(objFile.Name) = "txt" then
    DFC = objFile.Datecreated
    wscript.echo DFC
    ' change the "D" to "h" and then the < 2 to check on hours..
    IF (DateDiff("D", DFC, Date) < 2 ) then
        count = count + 1
        ' Can comment the filename output below... this was for testing only.
        Wscript.echo objFile.Name
    End IF
END IF

Next

IF count < 1 Then
'edit the text you want in the email sent to whatever you like if the FILES were NOT Generated...
'Wscript.echo "Files not generated"
objMessage.TextBody = "Files were NOT generated."
ELSE
'edit the text you want in the email sent to whatever you like if the FILES were Generated...
'Wscript.echo "Files were generated Fine... "
objMessage.TextBody = "Files were generated....."
END IF


objMessage.Subject = "File Generation check"
'FROM field
objMessage.From = "rahul.patel@met.com.au"
'TO Field
objMessage.To = "rahul.patel@met.com.au"
'objMessage.TextBody = "This is some sample message text."
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'you will need anonymous allowed on the mail server to be able to run this script to send email without authentication. Else
'objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Recommend using Basic Auth
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"

'The server below is for test purpose only. Suggest you get the correct server name.
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mtbexc08v.met.local"
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send

'just to test the count output.
'wscript.echo Count

Friday, August 17, 2012

Find service pack levels for Windows using powershell



Compile a list of servers, may be using another powershell script querying your AD container for servers.







The script below also does a ping test. To be honest, ping test doesn't really tell me if wmi query is going to work.

#$erroractionpreference = "SilentlyContinue"
$serverlist = Get-content 'C:\temp\Serverslist.txt.txt'

Foreach ($server in $serverlist)
{
    if((test-connection -computername $server -count 1 -ea 0 -quiet) -eq $true)

    {
    $serveros = Get-wmiobject -class win32_operatingsystem -computername $server
        foreach ($objserver in $serveros)
    {
        $server + "; " +$objserver.caption + "; " + $objserver.ServicePackMajorVersion
    }
   
    }
}

Tuesday, July 17, 2012

Time settings on Windows machines and Domain Controllers

To check windows time settings use the command below

check config using the command

w32tm /query /configuration
AND
w32tm /dumpreg /subkey:parameters



Recommend to use the following structure for windows time settings with in a Windows Domain.

Set the Domain controller with the PDC emulator to get the time from a reliable NTP source.
for e.g. 1.au.pool.ntp.org
Run the command below to set the settings for the above
w32tm /config /syncfromflags:manual /manualpeerlist:1.au.pool.ntp.org /update

If you cant get to the internet via port UDP 123 from the PDC emulator, then i recommend pointing the ntp server to a router or a esx host or a xenhost or a proxy server. You would need to then set the time source on the proxy to be a reliable source.

FOR Member servers, other DCs and Workstations on the Domain

RUN the commands below as bat if you like

@echo off
w32tm /config /syncfromflags:DOMHIER /update
w32tm /resync
@echo on

You can apply the above bat as a startup policy on workstations.

Have fun.

Hope it helps.




Thursday, April 26, 2012

RDP issue rdpcorekmts.dll Application error Event id 1000, Windows Server 2008 R2

One of the Win2k8R2 running client access Exchange as upgraded to SP1. Did the same for other servers. Only one came up with issue. Checked the version of rdpcorekmts.dll version on the server with issue
with issue: version 6.1.7600.16952
without issue with sp1 version: 6.1.7601.17514

Followed the solution from here:

http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/f5855b60-f29c-4c90-b364-e364589e5267

Just a quick note the file is update by Windows Update KB2667402 not KB2621440. Please see http://support.microsoft.com/kb/2667402 for more details.
1) Connect remotely to affected server using the Computer Management Console
2) Stop the Remote Desktop Services
3) Take Ownership of file C:\Windows\System32\rdpcorekmts.dll and assign full NTFS permissions to your account
4) Rename file to rdpcorekmts.old
5) Copy file rdpcorekmts.dll from a non-patched server. I used another one of our domain controllers just to be safe.
6) Start the Remote Desktop Services
7) Test RDP login to server

WORKED FINE.