Wednesday, December 17, 2014

How to Write into Event Viewer (using PowerShell)

I’m into a situation that I want to write the activity that was carried out into the Event Viewer (say the Application).

I’ve a PowerShell script but has incorporated the following in the beginning and the end of the script.

First I need to register the event into the server’s event viewer.  I call it as “InFront Maintenance”

In the PowerShell, I only execute once to record it down.

New-EventLog –LogName Application –Source “InFront Maintenance

Once it’s registered, then I incorporated the following into my beginning of my script the activity that I need to carry out. 

Note : If you do not register, the next line you execute to write to event viewer, you’ll definitely hit the error.  This is because the “SOURCE” is not registered.

Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “Maintenance Spoke A.

So in the event viewer you’ll be able to see something like this


At the end of my script I indicate as follow :

Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “End Maintenance Spoke A

In the event viewer you’ll see like this :


So to summary it :

To register for the first time the event (just once)

  • New-EventLog –LogName Application –Source “InFront Maintenance

Insert beginning on my PowerShell Script

  • Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “Maintenance Spoke A.

Insert at the end of my PowerShell Script

  • Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “End Maintenance Spoke A

Just change the Pink for your event, and the Yellow for the General Descriptions.

Thanks to the Scripting Guy Site , Ed Wilson!!

keynote : How to write to Event Viewer with powershell, using powershell to write event,event log, application log event viewer, eventviewer with PowerShell, record activity into event viewer

Friday, December 12, 2014

Drag and Drop Files into VM

I’ve a Windows 2012 R2 running Hyper-V.  A VM is running inside this Hyper-V but I need to copy some of the files into the VM.  One of the reason for not connecting to network is that the VM is cloned and I do not want to clash with the Production VM.

There’s a way that you can Drag and Drop into the VM from the Hyper-V Host into the VM.

Open the Hyper-V Settings – Click on the Enhanced Session Mode Policy.

Mark a check in the “Allow enhanced session mode” and click OK.


Once that is done, you can drag from your Hyper-V Host into the VM desktop or any folder that you want to copy into the VM.

Thank you and hope that helps.

keyword : drag and drop files, folders into VM that is not connected to network in Hyper-V host.

Thursday, December 11, 2014

Extending VHD / VHDX Volume

I have prepared the VHDX (or VHD in some cases) and it’s SYSPREP.  Now my C Drive is only 60GB but I would like to extend the hard disk to 100GB, to enable for me to install other applications on the C Drive.

I’m going to share how I do it.

My VHD is in the external drive (USB connected Hard Drive). 

Location E:\VHD\Demo

The VHD File is WIN81-ENT-x64-SYSPREP1.vhdx


I mount the drive to check on the space


As you can see it’s about 60GB. I’ll unmount and show the steps using DISKPART command

The command as follow :

  • Open Command Prompt with Administrator rights
  • Key in DISKPART
  • Next key in Select the Disk of where your VHD is located. For me is located at E Drive.  Therefore I key in as select vdisk file=”E:\VHD\Demo\WIN81-Ent-x64-SYSPREP.vhdx” 
  • Next to expand the TOTAL size of the VHD. I key in as expand vdisk maximum=100000
  • Next key in attach vdisk
  • Then key in list disk to view. If it’s not online then key on ONLINE DISK. It should be online automatically.


  • Next key in list volume
  • As you can see the volume shows as still 60GB
  • I key in as select volume 6
  • Key in extend
  • Key in list volume to see the new size


  • Opening up the attach disk, now it’s close to 100GB


Now I’m done, I would like to detach the VHD

Back to the DISKPART command prompt

  • Key in detach vdisk
  • Key in exit to quit diskpart from command prompt


In summary, I’ve keyed in as follow :

  • select vdisk file=”E:\VHD\Demo\WIN81-Ent-x64-SYSPREP.vhdx 
  • expand vdisk maximum=100000
  • attach vdisk
  • list disk
  • list volume
  • select volume 6
  • extend
  • list volume 
  • detach vdisk
  • exit 

Command in diskpart is in GREEN, you change those values in PINK 

Hopefully the steps are helpful.

keywords : diskpart, extend vhdx, extend vhd, expand volume size

Tuesday, April 15, 2014

DPM–An unexpected error occurred while the job was running (ID 104)


DPM tape taken from a Production site and imported into DPM in DR site.  Everything is successful and can view the content.  (Link on how to import external DPM tape is located here.)

The settings were follow :

  • Firewall has been allowed for DPM to communicate between the DPM server and the DR Test Restore server.
  • Antivirus has been made exclusions

Test results as follow :

  • Restore to DPM (DR site) local hard disk is successful
  • Restore from DPM (DR Site) to another server which is connected directly network cable in same segment of the backup vLAN is also successful
  • Restore from DPM (DR Site) to the DR Test Restore server failed.

The error showed in DPM is as follow when doing the restore :


The event viewer in the DPM showed as follow :

“Most or all jobs failed to recover the requested data (ID : 3111).  An unexpected error occurred while the job was running (ID : 104)”


After looking for sometime in Technet and blogs, there’s no solution. 

Then realised that the segment for the new DR Test Restore server is sitting in another segment.  It’s in another segment (  The entry had already been entered in the Host File (C:\Windows\System32\drivers\etc), however it’s still not working.

Then at last, found the issue was on the Backup vLAN configurations (Link to “How to force to use alternate Path for Backup (Backup VLAN) is located here).  So I edited to add in the 172 segment


After the entry was entered then I restarted the DPMRA services by elevated command prompt.

  • net stop dpmra
  • net start dpmra

After that I perform the restore from DPM in DR site to the DR Test Restore server, it was successful.

keywords  : An unexpected error occurred while the job was running ID : 104 , Most or all jobs failed to recover the requested data (ID : 3111) DPM restore, DPM backup failed restore.

Monday, April 7, 2014

How to check Disk Space Usage and Free Space Remotely using PowerShell

Scenario :

Two hyper-V Host (clustered) with multiple VMs in it.  I need to check on the disk allocation, disk space usage & disk free space.  With the script below I’m going to share how I did it using PowerShell.  I just run it in one of the Hyper-V Hosts PowerShell.

[Special credit to StackOverflow and BinaryNature.  I’ve made changes to ease the entry of variables]

The credential used in the script must be part of the local administrators group

# ----- Beginning of Script -----

#Define ServerName (Physical/VM) Here

# Change the Variables in PINK and remark out with # if the server or VM is not needed

# $APP2="APPVM2"
$DomainUser = "domain\user1"

# Diskfree Module

function Get-DiskFree
        [string[]]$ComputerName = $env:COMPUTERNAME,
        [System.Management.Automation.Credential()]$Credential =
        function Format-HumanReadable
            param ($size)
            switch ($size)
                {$_ -ge 1PB}{"{0:#.#'P'}" -f ($size / 1PB); break}
                {$_ -ge 1TB}{"{0:#.#'T'}" -f ($size / 1TB); break}
                {$_ -ge 1GB}{"{0:#.#'G'}" -f ($size / 1GB); break}
                {$_ -ge 1MB}{"{0:#.#'M'}" -f ($size / 1MB); break}
                {$_ -ge 1KB}{"{0:#'K'}" -f ($size / 1KB); break}
                default {"{0}" -f ($size) + "B"}
        $wmiq = 'SELECT * FROM Win32_LogicalDisk WHERE Size != Null AND DriveType >= 2'
        foreach ($computer in $ComputerName)
                if ($computer -eq $env:COMPUTERNAME)
                    $disks = Get-WmiObject -Query $wmiq `
                             -ComputerName $computer -ErrorAction Stop
                    $disks = Get-WmiObject -Query $wmiq `
                             -ComputerName $computer -Credential $Credential `
                             -ErrorAction Stop
                if ($Format)
                    # Create array for $disk objects and then populate
                    $diskarray = @()
                    $disks | ForEach-Object { $diskarray += $_ }
                    $diskarray | Select-Object @{n='Name';e={$_.SystemName}},
                        @{n='Size';e={Format-HumanReadable $_.Size}},
                        @{n='Used';e={Format-HumanReadable `
                        @{n='Avail';e={Format-HumanReadable $_.FreeSpace}},
                        /($_.Size) * 100))}},
                    foreach ($disk in $disks)
                        $diskprops = @{'Volume'=$disk.DeviceID;
                                   'Used'=($disk.Size - $disk.FreeSpace);
                        # Create custom PS object and apply type
                        $diskobj = New-Object -TypeName PSObject `
                                   -Property $diskprops
                        Write-Output $diskobj
                # Check for common DCOM errors and display "friendly" output
                switch ($_)
                    { $_.Exception.ErrorCode -eq 0x800706ba } `
                        { $err = 'Unavailable (Host Offline or Firewall)';
                            break; }
                    { $_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } `
                        { $err = 'Access denied (Check User Permissions)';
                            break; }
                    default { $err = $_.Exception.Message }
                Write-Warning "$computer - $err"
    END {}

$cred = Get-Credential -Credential $DomainUser
$PHY1, PHY2, $AD, $APP1, $APP2, $DB1, $DP1, $DPM1 | Get-DiskFree -Credential $cred -Format | Format-Table -GroupBy Name -AutoSize

# ----- End of Script -----


My method was copy the script above (from Beginning to End of the Script)  into a notepad and make changes only to the PINK.  Please include the “ “ quotes as in the scripts. 

(You can also save it as powershell script with ext of PS1 and run. Since this is a one time, I don’t intend to save it as PS1 file)

After making the necessary changes, I copied the text and launch the PowerShell (need to run as Administrator) from one of the Hosts


…then I paste into the PowerShell screen and press [Enter]


It will display the credential, key in the password :


It will display something like below with the (servername or VM name as I’ve hide) :


Happy trying  and hope the script helps as it helps me.

keywords : checking free space with powershell, powershell scripts, power shell script, checking space usage remotely, windows 2012 check disk space in VM

Thursday, April 3, 2014

Enabling Data Deduplication in my Windows 8.1

Recently my storage usage space in my drive is getting more and more and I’ve got to find a way to reduce it.  I read a few blogs and found a solution which is the dedup (I know that I have duplicate files in my drive but need sometime to housekeep Smile with tongue out )

This method is not officially supported by Microsoft however found a way to save my disk space.

This method requires the CAB files from the Windows Server 2012 R2.  Either you can get those files from a Windows Server 2012 R2 or you can download the files from my OneDrive here.

The files are as follow :


I downloaded the files to a folder as below :


Then in the command prompt I execute the following command (I executed in the particular folder where the files reside) :

dism /online /add-package / /  / /  / /

It looks something like below  :


Next I enable the Dedup Feature by executing the following command prompt:

dism /online /enable-feature /featurename:Dedup-Core /all

It looks something like below :


Verify your add/remove features in your Windows (launch the Programs and Features)


Next is launch the PowerShell (elevated mode)

Example below is I’m targeting on my D Drive (only change the one in yellow colour in the command for your target drive)

Enable-DedupVolume -Volume D:

Set-DedupVolume -Volume D: -OptimizeInUseFiles

It looks like :


To force the Dedup to start immediately, simply run the following command in Powershell

Start-DedupJob -Volume D: -Type Optimization


After waiting for a while, to monitor execute the command in powershell :

Get-DedupVolume -Volume D: | fl

It will display as below :


Special credit to Wei King and also Mailspintoys for their sharing.

Thank you

keywords : deduplicate, dedup, windows 8.1 dedup, reduce storage space, reduce disk space

Friday, March 28, 2014

Unable to Backup using DPM or Local Windows Backup–missing VSS

Here’s the scenario :

  • Two Windows Server 2012 running Hyper-V
  • Two Node Clusters
  • Backup software : DPM 2012 SP1

When the VM resides on Host1, the DPM can backup VMs with no issue.  However when the VMs resides in Host2, the DPM fails to backup.

Checked on the Host2 and found many errors of 8194.


To isolate further, I tried to backup Folders of Host2 using DPM, it still failed.  Additional to that, tried the Windows Backup locally on Host2, that too failed.

Next is to try a tool which comes in Windows Server 2008 and Windows Server 2012.  It’s called the Diskshadow.

Diskshadow > set context persistent
Diskshadow > set verbose on
Diskshadow > begin backup
Diskshadow > Add volume D: alias VolumeD

The output as follow :


Next I did a comparison of Host1 and Host2 by using the command as follow in the Diskshadow

Diskshadow > list providers

Found out that Host1 has all 4 but Host2 has only 2 of the providers.  The missing ones are highlighted in the pink box.


So go to the following registry in Host1:



Export both the missing key registry from Host1



Then in the Host2, I import both the keys that was exported above from Host1.

In the Host2, I use the Diskshadow to check the providers :


Tried the backup from DPM, and it’s working already.  Hope this helps . 

keywords : Microsoft Hyper-V VSS Writer failed retryable error, VSS Issue error 8194, DPM 2012 SP1, DPM backup fail ,

Creation of recovery points for Backup Using Child Partition Snapshot on have failed. The last recovery point creation failed for the following reason: (ID: 3114)
DPM encountered a retryable VSS error. (ID: 30112)

Monday, March 17, 2014

A VSS Writer has rejected an event with error 0x800423f3

Recently I hit the issue for the DPM backup the VMs.  The DPM backing the Hyper-V VMs failed with the following message in the event viewer of the Hyper-V host that the VM is residing.


Then in the command prompt (elevated “run as administrator”) I list the VSS by typing the command Vssadmin list writers.


In the DPM console, had the following :


The steps that I took to resolve the issue is as follow :

  • Shutdown the VM
  • Perform the VM backup through the DPM
  • In the Hyper-V host, launch the Hyper-V Manager and would be able to see the status as “backing up …”
  • Once the backup is completed in then I start up the VM.
  • Waited for 20 mins for the VM to be up and running, then perform another backup (create another recovery point in DPM)
  • It’s successful and case is resolve.

In the Hyper-V Host I run again the command prompt (elevated “run as administrator”) by typing the command Vssadmin list writers and check the status.


Hope it helps.

keywords : VSS, vssadmin, a vss writer has rejected an event with error 0x800423f3, the writer experienced a transient error, if the backup process is retried, the error may not reoccur, last error : retryable error, Microsoft Hyper-V VSS Writer, DPM encountered a retryable VSS error (ID 30112) , vssadmin list writers

Wednesday, February 19, 2014

Performance Monitor–Create Data Collector Set Greyed Out

Recently I tried to create a New Collector Set for the Performance Monitor for one of the customer’s request.  When I launched the Performance Monitor, click to create a new Data Collector Set and found it was greyed out.


After some troubleshooting, it seems that a service related to it was disabled.


All was done is click on the Properties of the Task Scheduler and select as Automatic Start Up.   You can click on the start to get the Task Scheduler instead of rebooting for this round.  Next time the server reboots, it will auto-start the services cause you have made the changes.

Once that’s done, go back to the Performance Monitor and create the new Data Collector Set, the Next button is no more grey out.

Hope this helps Smile.

keywords : Performance monitor, next button grey out greyed out, task scheduler, cannot create data collecter set

Monday, February 10, 2014

DPM–Fail to Erase the Tape or Backup to Tape

The Environment
Operating System : Windows 2008 R2
DPM Version : DPM 2010
Tape Library : IBM TotalStorage 3573 Tape Library with 1 drive

Issue faced when erasing or backup, the error prompted as failed.
Error Message : The operation failed because of a protection agent failure. (ID 998 Details: Access is denied (0x80070005))


After some troubleshooting, found there’s a way to resolve this issue.  I changed the Tape driver in the DPM server.

Steps carried out

  • Launch the Device Manager in the DPM server


  • Locate the Tape Drives and right click, select Update Driver Software


  • Select the “Let me pick from a list of device drivers on my computer


  • Select the LTO Tape Drive (which is a native driver)
  • Click Next till it’s finished.
  • Then in the DPM console, select the Management and rescan it.
  • Now the Tape Drive is ready and working once you perform the Erase or Backup.

Happy trying Smile

keywords : The operation failed because of a protection agent failure. (ID 998 Details: Access is denied (0x80070005)), tape data erase, tape backup, DPM 2010, DPM2010, DPM, Status Failed, IBM TotalStorage 3573 Tape Library

Wednesday, February 5, 2014

Logman Error : The System cannot find the path specified


As I was trying to create a Log using the LOGMAN command I hit the issue


It states as “The system cannot find the path specified

After some findings, the issue was the Task Scheduler was not started.  Therefore I went into the Services and enable and start the Task Scheduler.


Once Task Scheduler is started, I executed the command with no issue.


Hope this helps you.  Thanks to TechNet Social.

keywords : Logman, perfmon, system cannot find path specified, diagnostic tool.

Tuesday, January 28, 2014

DPM–How to Mark Tape as Free

Sometimes we hit the issue of having difficulty of marking the Tape as Free in the DPM Library.    The tape is label as “Unknown” at times and can’t mark it as Free in the DPM Console. Then I scout around and found that I need to do this in PowerShell.

Copy the following Script (in green) into a Notepad and place into a directory in the DPM server.  Rename it as a powershell extention.  I name it as ForceFree.ps1.

param ([string] $DPMServerName, [string] $LibraryName, [string[]] $TapeLocationList)

if(("-?","-help") -contains $args[0])
Write-Host "Usage: ForceFree-Tape.ps1 [[-DPMServerName] <Name of the DPM server>] [-LibraryName] <Name of the library> [-TapeLocationList] <Array of tape locations>"
Write-Host "Example: Force-FreeTape.ps1 -LibraryName "My library" -TapeLocationList Slot-1, Slot-7"
exit 0

if (!$DPMServerName)
$DPMServerName = Read-Host "DPM server name: "

if (!$DPMServerName)
Write-Error "Dpm server name not specified."
exit 1

if (!$LibraryName)
$LibraryName = Read-Host "Library name: "

if (!$LibraryName)
Write-Error "Library name not specified."
exit 1

if (!$TapeLocationList)
$TapeLocationList = Read-Host "Tape location: "

if (!$TapeLocationList)
Write-Error "Tape location not specified."
exit 1

if (!(Connect-DPMServer $DPMServerName))
Write-Error "Failed to connect To DPM server $DPMServerName"
exit 1

$library = Get-DPMLibrary $DPMServerName | where {$_.UserFriendlyName -eq $LibraryName}

if (!$library)
Write-Error "Failed to find library with user friendly name $LibraryName"
exit 1

foreach ($media in @(Get-Tape -DPMLibrary $library))
if ($TapeLocationList -contains $media.Location)
if ($media -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryManagement.ArchiveMedia])
foreach ($rp in @(Get-RecoveryPoint -Tape $media))
Get-RecoveryPoint -Datasource $rp.Datasource | Out-Null

Write-Verbose "Removing recovery point created at $($rp.RepresentedPointInTime) for tape in $($media.Location)."
Remove-RecoveryPoint -RecoveryPoint $rp -ForceDeletion -Confirm:$false

Write-Verbose "Setting tape in $($media.Location) as free."
Set-Tape -Tape $media -Free
Write-Error "The tape in $($media.Location) is a cleaner tape."

Double click on the DPM PowerShell in the DPM Server to launch the PowerShell

Type the powershell script that you’ve name it.  My example is ForceFree.ps1, therefore I keyed in as .\ForceFree.ps1

Then I keyed in the DPM Server Name, the Library Name and which slot of tape I want to Free it.


Once it’s done, then the tape can be re-use it.  Just go through the DPM Library and Erase it from the DPM Console.

Hope this helps. This article was simplified from TechNet.

keywords : DPM 2010, DPM 2012, DPM, free tape, mark tape as free, tape label as unknown, tape cannot erase