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

$PHY1="SVR1"
$PHY2="SVR2"
$AD1="ADVM1"
$APP1="APPVM1"
# $APP2="APPVM2"
$DB1="DBVM1"
$DP1="DPVM1"
$DPM1="DPMVM1"
$DomainUser = "domain\user1"

# Diskfree Module

function Get-DiskFree
{
    [CmdletBinding()]
    param
    (
        [Parameter(Position=0,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true)]
        [Alias('hostname')]
        [Alias('cn')]
        [string[]]$ComputerName = $env:COMPUTERNAME,
     
        [Parameter(Position=1,
                   Mandatory=$false)]
        [Alias('runas')]
        [System.Management.Automation.Credential()]$Credential =
        [System.Management.Automation.PSCredential]::Empty,
     
        [Parameter(Position=2)]
        [switch]$Format
    )
 
    BEGIN
    {
        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'
    }
 
    PROCESS
    {
        foreach ($computer in $ComputerName)
        {
            try
            {
                if ($computer -eq $env:COMPUTERNAME)
                {
                    $disks = Get-WmiObject -Query $wmiq `
                             -ComputerName $computer -ErrorAction Stop
                }
                else
                {
                    $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='Vol';e={$_.DeviceID}},
                        @{n='Size';e={Format-HumanReadable $_.Size}},
                        @{n='Used';e={Format-HumanReadable `
                        (($_.Size)-($_.FreeSpace))}},
                        @{n='Avail';e={Format-HumanReadable $_.FreeSpace}},
                        @{n='Use%';e={[int](((($_.Size)-($_.FreeSpace))`
                        /($_.Size) * 100))}},
                        @{n='FS';e={$_.FileSystem}},
                        @{n='Type';e={$_.Description}}
                }
                else
                {
                    foreach ($disk in $disks)
                    {
                        $diskprops = @{'Volume'=$disk.DeviceID;
                                   'Size'=$disk.Size;
                                   'Used'=($disk.Size - $disk.FreeSpace);
                                   'Available'=$disk.FreeSpace;
                                   'FileSystem'=$disk.FileSystem;
                                   'Type'=$disk.Description
                                   'Computer'=$disk.SystemName;}
                 
                        # Create custom PS object and apply type
                        $diskobj = New-Object -TypeName PSObject `
                                   -Property $diskprops
                        $diskobj.PSObject.TypeNames.Insert(0,'BinaryNature.DiskFree')
                 
                        Write-Output $diskobj
                    }
                }
            }
            catch
            {
                # 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 -----

Steps

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

image

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

image

It will display the credential, key in the password :

image

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

image

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 :

  • Microsoft-Windows-Dedup-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cab
  • Microsoft-Windows-Dedup-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cab
  • Microsoft-Windows-FileServer-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cab
  • Microsoft-Windows-FileServer-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cab
  • Microsoft-Windows-VdsInterop-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cab
  • Microsoft-Windows-VdsInterop-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cab

I downloaded the files to a folder as below :

image

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

dism /online /add-package /packagepath:Microsoft-Windows-VdsInterop-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cab /packagepath:Microsoft-Windows-VdsInterop-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cab  /packagepath:Microsoft-Windows-FileServer-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cab /packagepath:Microsoft-Windows-FileServer-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cab  /packagepath:Microsoft-Windows-Dedup-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cab /packagepath:Microsoft-Windows-Dedup-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cab

It looks something like below  :

image

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 :

image

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

image

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 :

image

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

Start-DedupJob -Volume D: -Type Optimization

image

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

Get-DedupVolume -Volume D: | fl

It will display as below :

image

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.

image

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.

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

The output as follow :

image

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.

image

So go to the following registry in Host1:

HKEY LOCAL MACHINE\SYSTEM\CURRENT CONTROL SET\SERVICES\VSS\PROVIDERS

image

Export both the missing key registry from Host1

image

image

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 :

image

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.

image

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

image

In the DPM console, had the following :

image

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.

image

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.

image

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

image

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))

SCR-154

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

image

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

SCR-152

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

SCR-153

  • 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

image

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.

image

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

image

Hope this helps you.  Thanks to TechNet Social.

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