Daily IT Matters, this is the place where I post my daily findings on IT.

Monday, November 02, 2009

Delete files older than x days using batch script

This one keeps coming back when you are administering several systems which are all pushing out some files to storage for example OLD SQL servers who are spitting out BAK files.


Forfiles /P D:\SQLbackup /S /M *.BAK /D -2 /C "cmd /c del /q @path"


Forfiles is standard included in windows since Windows 2000

Let me explain the switches I used.

/P |This one is for specifying the path.
/S |This is the same as in the dir command for recursively enumerating the files.
/M |Where you specify the search pattern to look for.
/D -2 |This is the most interesting part beacause this switch looks for files older or equal than 2 days.
/C |Here is where you specify what to do. If you want to start a command make sure it starts with cmd /c, I did a del command specifying the file by using the @path variable.

Wednesday, October 07, 2009

Starting a CMD prompt hidden for cacti poller.php

After implementing a CACTI monitoring environment at our customer on a windows platform (huh). We had a problem that our CACTI poller scheduled task was visible when it was started.

I first created this vbscript. To start the commandprompt hidden.

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("php c:\Apache2\htdocs\cacti\poller.php")



But this method is much better. Because it fits on 1 line!
CreateObject("Wscript.shell").run "php c:\Apache2\htdocs\cacti\poller.php",0

In short to run the cacti poller hidden you only have to schedule the above line in a vbscript every 5 minutes.

Wednesday, September 02, 2009

Netbackup Admin Script

Normal procedure for NetBackup with our Robot with 2 LTO4 tapes is physically adding media then do an inventory and then check in the gui your retention period for the tapes.
I've written a script which does all that. The only thing you need to change part where I let findstr search for eg LTO4 (all our LTO4 tapedrives use a pool with LTO4 in the name)



@echo off
e:
cd "\Program Files\Veritas\Volmgr\bin"

Rem *****************
REM * Inventory Robot
REM *****************

vmupdate -rt TLD -rn 1 -h hpbck01 -rh hpbck01 -use_barcode_rules

Rem **************
Rem * Expire Media
REM **************

for /f "delims=, " %%a in ('"vmquery -rn 1 -bx findstr /I "LTO4""') do
"E:\Program Files\Veritas\NetBackup\bin\admincmd\bpexpdate.exe" -d 0 -ev %%a
-force

Rem ****************************
Rem * Move media to scratch pool
REM
****************************

for /f "delims=, " %%b in ('"vmquery -rn 1 -bx findstr /I "NetBackup""') do
vmchange -p 4 -m %%b

Tuesday, August 11, 2009

Recover Deleted Items Outlook 2000

By default, the Recover Deleted Items functionality is only enabled on the Deleted Items folder in a user's private folders. Items that are hard deleted cannot be recovered. To enable the Recover Deleted Items functionality on mail folders other than the Deleted Items folder (for example, for the Sent Items, Drafts, Outbox and Inbox folders), make the following changes to the registry:

  1. Start Registry Editor.
  2. Locate and then click the following key in the registry:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Exchange\Client\Options

  3. On the Edit menu, click Add Value, and then add the following registry value:

    Value name: DumpsterAlwaysOn
    Data type: DWORD
    Value data: 1

  4. Close Registry Editor.

You can use an administrator's computer or a user's computer to make this change to the registry. After you change the registry, start Outlook, and then click Deleted Item Recovery on the Tools menu. A list of items that were hard deleted during the retention time that is set on the server is displayed.

If you are an administrator, you can set this functionality for all user workstations. To do this, use your computer to change the registry for all user workstations, and then open the affected user's mailbox as an additional mailbox. You can then recover deleted items from the user's mailbox mail folders.

Note If you are an administrator, and you want to open another user's mailbox to recover items in the user's private folders, your Windows NT account must have User permissions for that user's mailbox object. You must also add that user's mailbox to your own profile. To do this, follow these steps:

  1. Open Control Panel, and then double-click Mail.
  2. Open the Services properties, and then double-click Microsoft Exchange Server.
  3. Click the Advanced tab, and then click Add to add the mailbox to your profile.

Monday, August 10, 2009

Copy fonts using script for unattended vista install

I had to create a vbscript to copy fonts from a network share for an unattended vista (or windows 7) install


Const FONTS = &H14&
Set objShell = CreateObject("shell.Application")
Set objFolder = objShell.Namespace(FONTS)
strdir = "\\srv001\REMINST\Drivers\Finalize\Fonts"

enumdir(strdir)

Sub EnumDir(strdir)
dim FSO,f,fc
set FSO=Wscript.CreateObject("scripting.FileSystemObject")
If fso.FolderExists(strDir) then
set f=fso.GetFolder(strDir)
set fc=f.files
if fc.Count > 2 then
for each fl in fc
objFolder.CopyHere strdir & "\" & fl.name
next
End If
else
wscript.echo "Folder " & strDir & " NOT found"
end if
End Sub

Wednesday, March 04, 2009

Terminal Server Profile Path Woes

During a migration process I came accross this odd problem.
I could not change a Terminal Server Profile Path for a couple of hundred users.

I searched the microsoft site but I could not find anything that would help me quick.
Yes I did find this link http://technet.microsoft.com/en-us/library/cc783578.aspx

But my client did not have grouppolicies in place and I did not want to use the "Terminal Services Extension"

I found several partly usefull scripts I combined the best of them in the script below. I really hope you will find this usefull.


'******************************************************************************
Const ADS_SCOPE_SUBTREE = 2
Const ForAppending = 8

On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\myusers.txt", ForAppending, True)

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
'Change the below LDAP query to select the users in your correct OU
objCommand.CommandText = "Select sAMAccountName,name from 'LDAP://OU=Users,OU=_GlobalResources,OU=e178,DC=emea,DC=corpdir,DC=net' " & "Where objectClass='user'"

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
objTextFile.WriteLine(objRecordSet.Fields("sAMAccountName").Value)
objRecordSet.MoveNext
Loop

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\myusers.txt", 1, True)
Set objTextFile2 = objFSO.OpenTextFile("c:\myresults.txt", 8, True)

Dim arrUsers()
i = 0

Do Until objTextFile.AtEndOfStream
Redim Preserve arrUsers(i)
arrUsers(i) = objTextFile.ReadLine
i = i + 1
Loop

objTextFile.Close

For Each myUser in arrUsers

'in de my user file staan samAccounts hiermee kan je ldap niet bevragen dit zou via ado moeten.
'er is echter een methode om een samAccount om te zetten in een DN.

Dim objUser

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

strNetBIOSDomain = "your_netbios_domain_name" ' <-- change this
strNTName = myUser

Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
strUserDN = Replace(strUserDN, "/", "\/")

Set objUser = GetObject("LDAP://" & strUserDN)

strTSPath = objUser.TerminalServicesProfilePath
strOudeServer = "old_server_name" '<-- change this
strNieuweServer = "new_server_name" '<-- change this

strTSPath_new = Replace(strTSPath,strOudeServer,strNieuweServer)

If Mid(strTSPath,3,8) = strOudeServer Then

'Display some logging
objTextFile2.WriteLine(myUser)
objTextFile2.WriteLine("Terminal Server Profile Path OLD: " & objUser.TerminalServicesProfilePath)
objTextFile2.WriteLine("Terminal Server Profile Path NEW: " & strTSPath_new)

'### The Actual change takes place here.

objUser.TerminalServicesProfilePath = strTSPath_new
objUser.setinfo

'####################################################################

End If
Next

objTextFile2.Close
'******************************************************************************
Google