Need to know if the c: drive on your inventoried systems are fragmented? We do, we also need to defrag them regularly. Here is how I am going to do it. I am piloting this as I type this documentation.
I have written a script using Wise Scripting. I have attached a ZIP file containing the WSE file and the compiled EXE file.
The script runs the defrag.exe command in WindowsXP with -a to analyze the fragmentation, then dumps it to a temporary txt file. It then does some parsing of that file to get the level of fragmentation and whether a defrag is suggested or not. Then it turns those into variables. It then uses the information it has found to create an NSI file for Altiris Inventory Solution. After Inventory Solution collects this info there is now a table in the Altiris DB named Inv__DriveFragmentation_Inv.
To get this into Inventory copy the DriveFragCustInv.EXE file into the \\server\NSCap\Bin\Win32\X86\Inventory Solution folder on your NS server. Then create an INI file named AeXInvSolnDriveFrag1.ini with the following:
DriveFragCustInv.EXE
aexnsinvcollector.exe /hidden /nsctransport /v default /useguidOpen up Inventory Solution in NS.
In NS setup the Inventory package and task
View > Solutions > Inventory Solution
Expand 'Tasks > Windows > Inventory Tasks' then select one of your current tasks. For example, Software Inventory.
Click 'Go To Program'. You will get the page to modify the package.
Click the new button and enter the following then click Apply and close the window:
Name: Drive Fragmentation definition file
Command line: aexinvsoln.exe /hidden /s AeXInvSolnDriveFrag1.ini
Estimated disk space: 124
Estimated run time: 1
Terminate after: 10
After running: No action required
Start window: Hidden
Run with rights: System Account
Program can run: Whether or not a user is logged on
Minimum connection speed: No network connection required
Right click on 'Software Inventory' and choose Clone. Give the new task a name like 'Drive Fragmentation Inventory'
Select Enable for the new task. Choose program name 'Drive Fragmentation definition file'. Select the collection(s) you want this to run against and when you want it to run.
Here is an example of my task.
When the systems start to report in they will run this custom inventory and the table will be created in the Altiris DB.
Here is an example of a report I created to gather this info. In 'Reports > All Reports' right click on User Defined and choose 'New > Report'
In the report wizard enter a name for your report and choose Enter SQL Directly. Insert the follow SQL statement and click Finish:
select vc.[Name],
df.[Fragmentation] as 'C: Drive Fragmentation',
df.[Recommendation] as 'Microsoft Recommended Action' ,
vc.[guid] as '_Resourceguid'
from dbo.inv__DriveFragmentation_Inv df
left join dbo.vComputer vc on vc.[guid] = df.[_Resourceguid]
order by vc.[Name]
You can now run your report to get the amount of fragmentation on your systems C: drive.
Now you can create a collection of systems that need to be defragmented.
In your console click View > Resources
Expand Collections and right click on the folder you want your collection to reside in and choose New > Collection.
Type a name for your collection, for example, 'Systems that need their C: drive defragmented'.
In the Query section select Resource Type of Computers then click where is says 'No Filters'. Click the 'New Filter...' button. Select the Inv__DriveFragmentation_Inv table, the Recommendation field, and the value of 'You Should defragment this volume'.
Click OK, the Manage Filters window should now show the filter.
Click OK and Apply to finish creating the collection.
Now you can create a Software Delivery task to run against this collection and defragment the drives that need it. I'm sure there are other ways to use task server, etc against the collection. I just don't currently have that implemented so I am going 'old school'. I could have even written the Wise script to do the defrag at the time of the inventory, but I wanted to keep the process' separate, just in case I want to stop defragging and keep getting the inventory.
For example I am running my custom inventory at noon and will run the Software Delivery task every day at 8PM against this collection.
Click View > Solutions > Software Delivery. Expand Tasks > Windows > Software delivery Tasks, then click on the 'Wizard and Status'. You can use this Wizard to create the package to defrag and the task to do it.
Click the Run button to start the Wizard.
Select Create and deliver a new package of software. For the Source select that the package does not contain source files. In the command line type: defrag.exe c: Then click Next
Select System Account for the run rights. Select whether or not a user is logged in and de-select User Input Required. Change the window style to hidden. Click Next
Select your collection of systems that need their drive defragged. Select a time to run this daily, remember this won't run against all systems daily, just the systems in the collection. I also select to run this as soon as possible after the time, this may not be an option you want in your environment. I also select WOL and user can run the task.
Change your Software delivery task name, Package name, and program name to something that makes sense in your environment and click OK. See my screenshot.
You should now have a SWD task similar to this one.
Your mileage may vary with this process. I am just starting out with this process. I'd like to know if this works for others or is necessary in other peoples environments. With budget crunches and such we need to make our systems last longer that the traditional 3 years and we are hoping this will help some with performance.