Script

Deduplication with Powershell

On my lab machines I try to enable and run the deduplication feature to save space for my Virtual Machines. I have below listed the commands for my own reference.

Install and enable Deduplication in Windows Server 2012 R2 with Powershell in my case I enable Dedup on volume D: in my example.

Install-windowsFeature FS-Data-Deduplication
Enable-DeDupVolume D:

To list the jobs that are added runthis command

Get-DedupSchedule

Start a Deduplication job manually with Powershell

 Start-DedupJob –Full –Path D: -Type Optimization

To see the status of whats going on with running Dedup jobs

Get-DedupJob

To see how much Dedup has saved for you simply run

Get-DedupStatus

 

Setting cache size on clients with script

Do you want to change the SMS/SCCM client cache size setting in your environment you can do this with a script. I will show you 2 examples of doing it.

On Error Resume Next
 Set oUIResource = CreateObject("UIResource.UIResourceMgr")
Set objCacheInfo = oUIResource.GetCacheInfo
 nValueToSet = 20480
 objCacheInfo.TotalSize = nValueToSet

If you would like to deploy it via SMS/SCCM with different sizes you can use the script below. Save it as a ex. setclientcachesize.vbs script and create a folder in our package area and create different programs for it.

  • setclientcachesize.vbs 10240
  • setclientcachesize.vbs 15360
  • setclientcachesize.vbs 20480

If you would like to set your client cache size to a static value a script like this would to it. Save the code and save it as a .vbs script, and deploy in preferred way. To change the size change the value 20480 to preferred value in MB.

On Error Resume Next
 Set oUIResource = CreateObject("UIResource.UIResourceMgr")
Set objCacheInfo = oUIResource.GetCacheInfo
 nValueToSet = wscript.arguments(0)
 objCacheInfo.TotalSize = nValueToSet

 

Delete files older then x days

When I configure System Center Configuration Manager I always setup a cleanup job to delete certain files that will fill up the disks. An example is the IIS log files that potentially will grow allot. So first I move them off the default location on the C drive to another content drive, and then I configure a scheduled task to run a script that removes older files. I usually keep 7 days of logs for troubleshooting purposes.

Below you have a sample script to delete files older then 7 days. It can easily be changed for your own preferences.

'This is a script to delete files older then specified days
Option Explicit

Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld
'iDaysold = Delete files older then x amount of days
iDaysOld = 7

'sDirectoryPath = "Folder to deleteFiles in"
sDirectoryPath = "C:Tempforanexample"

On Error Resume Next

Set oFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(sDirectoryPath) Then
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
oFile.Delete(True)
End If
Next
else
WScript.Echo "No Folder"
End If

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing