Thursday, November 7, 2024

DELL hardware sensors(Fan/CPU/DIMM modules/Temperature/AMP/VLT/WATTS) monitoring for Windows platform using DELL openmanage MSI package with WMI classes enabled.

# The below code requires DELL openmanager with WMI enabled classes to be installed, to fetch appropriate classes to get the hardware status.


param(

    [Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)]

    [System.String] $component # this will take parameter as fan,memory,cpu,temp,amp,vlt,watt


)

#Write-host $component


function convertUnitModifier{

param (

        [int16]$unitModifier,

        [int32]$convCurrentReading

)


    switch ($unitModifier)

    {

         0 { return($convCurrentReading) }

        -1 { return($convCurrentReading/10) }

        -2 { return($convCurrentReading/100) }

        -3 { return($convCurrentReading/1000) }

        -4 { return($convCurrentReading/10000) }

        -5 { return($convCurrentReading/100000) }

        -6 { return($convCurrentReading/1000000) }

        default { return ($convCurrentReading) }

    }



}



try

{


$ok_flag="" 

$war_flag=""

$cri_flag=""

$unknown_flag=""

$undetermind_flag=""

$ObjChassis = Get-WmiObject -Namespace root\cimv2\dell -class CIM_Chassis | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #Chassi info



# Fan sensor check

If( $component -eq "fan")

    {

    # Fan Status property return states mapped w.r.t Nagios #change as required to the tool processing logic

    #OK ("OK"); return(0)

    #Error ("Error"); return(2)

    #Degraded ("Degraded"); return(2)

    #Unknown ("Unknown"); return(3)

    #Pred Fail ("Pred Fail"); return(2)

    #Starting ("Starting"); return(1)

    #Stopping ("Stopping"); return(1)

    #Service ("Service"); return(1)

    #Stressed ("Stressed"); return(2)

    #NonRecover ("NonRecover") or "Non-recover"; return(2)

    #No Contact ("No Contact"); return(2)

    #Lost Comm ("Lost Comm") return(3)

    $ObjFanRpm = Get-WmiObject -Namespace root\cimv2\dell -class CIM_Tachometer | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- Fans

    $fname=@()

    foreach($fan in $ObjFanRpm)

        {

          if($fan.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($fan.Status -eq "Starting" -or $fan.Status -eq "Stopping" -or $fan.Status -eq "Service")

            {

             $war_flag=1

            }

          elseif($fan.Status -eq "Error" -or $fan.Status -eq "Degraded" -or $fan.Status -eq "Pred Fail" -or $fan.Status -eq "Stressed" -or $fan.Status -eq "NonRecover" -or $fan.Status -eq "No Contact" -or $fan.Status -eq "Non-recover")

            {

             $cri_flag=2

            }

          elseif($fan.Status -eq "Unknown" -or $fan.Status -eq "Lost Comm")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            $f_format= $fan.Status+":"+$fan.Name+":"+$fan.CurrentReading + "rpm;"

          $fname=$fname + $f_format

        }

         # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$fname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$Fname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$Fname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$Fname"

            exit($ok_flag)

            }

    

      

    }


If($component -eq "temp")

   {

    $ObjTemp = Get-WmiObject -Namespace root\cimv2\dell -class CIM_TemperatureSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID  #- Temperature divide it by 10 to get the value in Degree Celcius

    $tname=@()

    $tempConv=@()

    foreach ($temp in $ObjTemp)

    {

    $ObjTempConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName

    $conv_temp=convertUnitModifier -unitModifier $temp.UnitModifier -convCurrentReading $temp.CurrentReading

    $ObjTempConv.DeviceID = $temp.DeviceID

    $ObjTempConv.Name = $temp.Name

    $ObjTempConv.CurrentReading = $conv_temp

    $ObjTempConv.Status=$temp.Status

    $ObjTempConv.SystemName = $temp.SystemName

    $tempConv = $tempConv + $ObjTempConv

    }

    foreach($temp in $tempConv)

        {

          if($temp.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($temp.Status -eq "Starting" -or $temp.Status -eq "Stopping" -or $temp.Status -eq "Service")

            {

             $war_flag=1

            }

          elseif($temp.Status -eq "Error" -or $temp.Status -eq "Degraded" -or $temp.Status -eq "Pred Fail" -or $temp.Status -eq "Stressed" -or $temp.Status -eq "NonRecover" -or $temp.Status -eq "No Contact" -or $temp.Status -eq "Non-recover")

            {

             $cri_flag=2

            }

          elseif($temp.Status -eq "Unknown" -or $temp.Status -eq "Lost Comm")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            $t_format= $temp.Status+":"+$temp.Name+":"+$temp.CurrentReading + "DegCel;"

          $tname=$tname + $t_format

        }

         # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$tname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$tname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$tname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$tname"

            exit($ok_flag)

            }


  }


If($component -eq "pwr")

   {

    $ObjPwrWatt = Get-WmiObject -Namespace root\cimv2\dell -class DELL_PowerConsumptionWattsSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- PoweSupply Watt

    $pname=@()

    $pwrConv=@()

    foreach ($pwr in $ObjPwrWatt)

    {

    $ObjPwrWattConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName

    $conv_pwr=convertUnitModifier -unitModifier $pwr.UnitModifier -convCurrentReading $pwr.CurrentReading

    $ObjPwrWattConv.DeviceID = $pwr.DeviceID

    $ObjPwrWattConv.Name = $pwr.Name

    $ObjPwrWattConv.CurrentReading = $conv_pwr

    $ObjPwrWattConv.Status=$pwr.Status

    $ObjPwrWattConv.SystemName = $pwr.SystemName

    $pwrConv = $pwrConv + $ObjPwrWattConv

    }

    foreach($pwr in $pwrConv)

        {

          if($pwr.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($pwr.Status -eq "Starting" -or $pwr.Status -eq "Stopping" -or $pwr.Status -eq "Service" -or $pwr.Status -eq "Warning" -or $pwr.Status -eq "Predictive Failure")

            {

             $war_flag=1

            }

          elseif($pwr.Status -eq "Error" -or $pwr.Status -eq "Degraded" -or $pwr.Status -eq "Pred Fail" -or $pwr.Status -eq "Stressed" -or $pwr.Status -eq "NonRecover" -or $pwr.Status -eq "No Contact" -or $pwr.Status -eq "Non-recover" -or $pwr.Status -eq "Non-Recoverable Error" -or $pwr.Status -eq "Non-Recoverable" -or $pwr.Status -eq "Aborted")

            {

             $cri_flag=2

            }

          elseif($pwr.Status -eq "Unknown" -or $pwr.Status -eq "Lost Comm" -or $pwr.Status -eq "Lost Communication")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            

            $p_format= $pwr.Status+":"+$pwr.Name+":"+$pwr.CurrentReading + "W;"

          $pname=$pname + $p_format

        }


        # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$pname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$pname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$pname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$pname"

            exit($ok_flag)

            }


   }



 If($component -eq "amp")

   {

    $ObjPwrAmp = Get-WmiObject -Namespace root\cimv2\dell -class DELL_PowerConsumptionAmpsSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- PoweSupply Current (CurrentValue*10^-1) - 10^-1 is the unitmodifier

    $aname=@()

    $pwraConv=@()

    foreach ($pwra in $ObjPwrAmp)

    {

    $ObjPwrAmpConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName

    $conv_pwra=convertUnitModifier -unitModifier $pwra.UnitModifier -convCurrentReading $pwra.CurrentReading

    $ObjPwrAmpConv.DeviceID = $pwra.DeviceID

    $ObjPwrAmpConv.Name = $pwra.Name

    $ObjPwrAmpConv.CurrentReading = $conv_pwra

    $ObjPwrAmpConv.Status=$pwra.Status

    $ObjPwrAmpConv.SystemName = $pwra.SystemName

    $pwraConv = $pwraConv + $ObjPwrAmpConv

    }

    foreach($pwra in $pwraConv)

        {

          if($pwra.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($pwra.Status -eq "Starting" -or $pwra.Status -eq "Stopping" -or $pwra.Status -eq "Service" -or $pwra.Status -eq "Warning" -or $pwra.Status -eq "Predictive Failure")

            {

             $war_flag=1

            }

          elseif($pwra.Status -eq "Error" -or $pwra.Status -eq "Degraded" -or $pwra.Status -eq "Pred Fail" -or $pwra.Status -eq "Stressed" -or $pwra.Status -eq "NonRecover" -or $pwra.Status -eq "No Contact" -or $pwra.Status -eq "Non-recover" -or $pwra.Status -eq "Non-Recoverable Error" -or $pwra.Status -eq "Non-Recoverable" -or $pwra.Status -eq "Aborted")

            {

             $cri_flag=2

            }

          elseif($pwra.Status -eq "Unknown" -or $pwra.Status -eq "Lost Comm" -or $pwra.Status -eq "Lost Communication")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            

            $pa_format= $pwra.Status+":"+$pwra.Name+":"+$pwra.CurrentReading + "A;"

          $aname=$aname + $pa_format

        }


        # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$aname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$aname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$aname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$aname"

            exit($ok_flag)

            }


   }


  If($component -eq "vlt")

   {

    $ObjPwrVlt = Get-WmiObject -Namespace root\cimv2\dell -class CIM_VoltageSensor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID #- PoweSupply Voltage

    $vname=@()

    $pwrvConv=@()

    foreach ($pwrv in $ObjPwrVlt)

    {

    $ObjPwrVltConv = "" | Select-Object DeviceID,Name,CurrentReading,Status,SystemName

    $conv_pwrv=convertUnitModifier -unitModifier $pwrv.UnitModifier -convCurrentReading $pwrv.CurrentReading

    $ObjPwrVltConv.DeviceID = $pwrv.DeviceID

    $ObjPwrVltConv.Name = $pwrv.Name

    $ObjPwrVltConv.CurrentReading = $conv_pwrv

    $ObjPwrVltConv.Status=$pwrv.Status

    $ObjPwrVltConv.SystemName = $pwrv.SystemName

    $pwrvConv = $pwrvConv + $ObjPwrVltConv

    }

    foreach($pwrv in $pwrvConv)

        {

          if($pwrv.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($pwrv.Status -eq "Starting" -or $pwrv.Status -eq "Stopping" -or $pwrv.Status -eq "Service" -or $pwrv.Status -eq "Warning" -or $pwrv.Status -eq "Predictive Failure")

            {

             $war_flag=1

            }

          elseif($pwrv.Status -eq "Error" -or $pwrv.Status -eq "Degraded" -or $pwrv.Status -eq "Pred Fail" -or $pwrv.Status -eq "Stressed" -or $pwrv.Status -eq "NonRecover" -or $pwrv.Status -eq "No Contact" -or $pwrv.Status -eq "Non-recover" -or $pwrv.Status -eq "Non-Recoverable Error" -or $pwrv.Status -eq "Non-Recoverable" -or $pwrv.Status -eq "Aborted")

            {

             $cri_flag=2

            }

          elseif($pwrv.Status -eq "Unknown" -or $pwrv.Status -eq "Lost Comm" -or $pwrv.Status -eq "Lost Communication")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            

            $pv_format= $pwrv.Status+":"+$pwrv.Name+":"+$pwrv.CurrentReading + "v;"

          $vname=$vname + $pv_format

        }


        # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$vname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$vname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$vname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$vname"

            exit($ok_flag)

            }


   }


 If($component -eq "processor")

   {

    $ObjProcessor = Get-WmiObject -Namespace root\cimv2\dell -class CIM_Processor | Select-Object DeviceID,Name,CurrentReading,Status,SystemName,UnitModifier|Sort-Object DeviceID # CPU health

    $pname=@()

    $ProcessorConv=@()

    foreach ($Processor in $ObjProcessor)

    {

          if($Processor.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($Processor.Status -eq "Starting" -or $Processor.Status -eq "Stopping" -or $Processor.Status -eq "Service" -or $Processor.Status -eq "Warning" -or $Processor.Status -eq "Predictive Failure")

            {

             $war_flag=1

            }

          elseif($Processor.Status -eq "Error" -or $Processor.Status -eq "Degraded" -or $Processor.Status -eq "Pred Fail" -or $Processor.Status -eq "Stressed" -or $Processor.Status -eq "NonRecover" -or $Processor.Status -eq "No Contact" -or $Processor.Status -eq "Non-recover" -or $Processor.Status -eq "Non-Recoverable Error" -or $Processor.Status -eq "Non-Recoverable" -or $Processor.Status -eq "Aborted")

            {

             $cri_flag=2

            }

          elseif($Processor.Status -eq "Unknown" -or $Processor.Status -eq "Lost Comm" -or $Processor.Status -eq "Lost Communication")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            

            $Processor_format= $Processor.Status+":"+$Processor.Name + ";"

          $pname=$pname + $Processor_format

        }


        # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$pname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$pname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$pname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$pname"

            exit($ok_flag)

            }


   }


 If($component -eq "memory")

   {

    $ObjMem = Get-WmiObject -Namespace root\cimv2\dell -class CIM_PhysicalMemory | Select-Object Name,Status|Sort-Object Name # Memory Health

    $mname=@()

    foreach ($Memory in $ObjMem)

    {

   

          if($Memory.Status -eq "OK")

            {

             $ok_flag=0

            }

          elseif($Memory.Status -eq "Starting" -or $Memory.Status -eq "Stopping" -or $Memory.Status -eq "Service" -or $Memory.Status -eq "Warning" -or $Memory.Status -eq "Predictive Failure")

            {

             $war_flag=1

            }

          elseif($Memory.Status -eq "Error" -or $Memory.Status -eq "Degraded" -or $Memory.Status -eq "Pred Fail" -or $Memory.Status -eq "Stressed" -or $Memory.Status -eq "NonRecover" -or $Memory.Status -eq "No Contact" -or $Memory.Status -eq "Non-recover" -or $Memory.Status -eq "Non-Recoverable Error" -or $Memory.Status -eq "Non-Recoverable" -or $Memory.Status -eq "Aborted")

            {

             $cri_flag=2

            }

          elseif($Memory.Status -eq "Unknown" -or $Memory.Status -eq "Lost Comm" -or $Memory.Status -eq "Lost Communication")

            {

             $unknown_flag=3

            }

          else

            {

             $undetermind_flag=4

            }

            

            $Memory_format= $Memory.Status+":"+$Memory.Name + ";"

          $mname=$mname + $Memory_format

        }


        # IF none of the status values matches then consider it as Critical

        if($undetermind_flag -eq 4)

            {

             $cri_flag=2

            }

        # detrmine the state of the matched status to return the value from plugin and exit the shell

            If($cri_flag -eq 2)

            {

            Write-Host "$mname"

            exit($cri_flag)

            }

            if($war_flag -eq 1)  

            { 

            Write-Host "$mname"

            exit($war_flag)

            }

            if($unknown_flag -eq 3)

            {

            Write-Host "$mname"

            exit($unknown_flag)

            }

            if($ok_flag -eq 0)

            {

            Write-Host "$mname"

            exit($ok_flag)

            }


   }


}

catch

{

   

Write-Host "Exception occured."

$e = $_.Exception

$msg = $e.Message

while ($e.InnerException) 

 {

  $e = $e.InnerException

  $msg += "`n" + $e.Message

 }

  Write-Host $msg


}

 

Wednesday, July 13, 2022

Virtual machine re-registration, disconnected virtual machine/ read-only VM virtual machine- VMWARE - PowerShell

 Import-Module VMware.VimAutomation.Core

#Run this by opening VMware PowerCLI tool and connect using connect-VIserver

$pscrd = Get-Credential

Connect-VIServer -Server 10.106.202.151 -Credential $pscrd

Write-Host "Current script directory is $ScriptDir"


$CurrDate = Get-Date -Format "yyyyMMdd_HHmmss"

$SubCurrDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss"


$agree= "N"

Write-Host "Before you run the code. Makesure, to have required back-up of VMs for any recovery" -BackgroundColor DarkRed

$agree = Read-Host "You want to proceed: Y/N"

If( $agree -eq "Y" -or $agree -eq "y" )

{

#Flag to validate the ZERO Byte VMs

$flag=0

# This will get us the complete list of VMs in the inventory

#$vms = Get-VM

$vms = Get-VM #-Name TESTVM_KDC_03

$status_coll = @()

$vm_coll = @()

# Loop-in throught the Vm with various validation and checks

foreach($vm in $vms)

{


$regvm = "" | Select-Object VMName,PowerState,UsedSpaceGB,vmPathName,Remarks

$vm_state = "" | Select-Object VMName,PowerState,UsedSpaceGB,vmPathName,Remarks

  If($vm.UsedSpaceGB -eq 0 -And $vm.PowerState -eq "PoweredOn")

    {

         # If a VM is found to be a Zero byte space

         # execute the registration process

         $flag=1

         $vmname = $vm.Name

         #Write-Host "This is a Zero Byte VM and is in PowerON state: $vm.Name"

         #code to re-register the VM from the Inventory

         $resourcePool = Get-ResourcePool -VM $vm

         $vmPathName = $vm.ExtensionData.Config.Files.VmPathName

        #VM resource details

        $vm_state.VMName = $vmname

         $vm_pstate = $vm.PowerState

         $vm_state.PowerState = $vm_pstate

         $vm_usedspaceGB = $vm.UsedSpaceGB

         $vm_state.UsedSpaceGB = $vm_usedspaceGB

        $vm_state.vmPathName = $vmPathName

         $vm_state.Remarks = "DataCollection"

         get-vm $vmname | Stop-VM -confirm:$false

         $vm_stp_status = get-vm $vmname

         #Validate VM status condition block to remove from Inventory and re-registration

         If($vm_stp_status.PowerState -eq "PoweredOff") 

         {

          

             # Knock off the VMs from the Inventory without deleting the vmx file from the pool

           # Which is made as false and never make it true or remove the below Switch else Data loss will happen

            #Cautious note touch the below line only when you are aware what you are doing.

             Remove-VM -VM $vm -DeletePermanently:$false -Confirm:$false

             New-VM -VMFilePath $vmPathName -ResourcePool $resourcePool -Confirm:$false

            $vm_new_status = get-vm $vmname

             start-vm $vm_new_status -confirm:$false

                  $vm_strt_status = get-vm $vmname

                  #If the start of VM is successfull on the return

                    If($vm_strt_status.PowerState -eq "PoweredOn" -and $vm_strt_status.UsedSpaceGB -ne 0)

                      {

                       # Collect the server saying sucessfull registration

                       $regvm.VMName = $vmname

                       $vm_strt_pstate = $vm_strt_status.PowerState

                       $regvm.PowerState = $vm_strt_pstate

                       $vm_strt_usedspaceGB = $vm_strt_status.UsedSpaceGB

                       $regvm.UsedSpaceGB = $vm_strt_usedspaceGB

                       $regvm.vmPathName = $vmPathName

                       $regvm.Remarks = "Registered successfully"

                      }

                    Else

                      {

                       $regvm.VMName = $vmname

                       $vm_strt_pstate = $vm_strt_status.PowerState

                       $regvm.PowerState = $vm_strt_pstate

                       $vm_strt_usedspaceGB = $vm_strt_status.UsedSpaceGB

                       $regvm.UsedSpaceGB = $vm_strt_usedspaceGB

                       $regvm.vmPathName = $vmPathName

                       $regvm.Remarks = "Couldn't register, Please check Manually"

                      }            

           }

           Else

           {

            #Couldn't stop VM for re-registration process

            $regvm.VMName = $vmname

            $vm_stp_pstate = $vm_stp_status.PowerState

            $regvm.PowerState = $vm_stp_pstate

            $vm_strt_usedspaceGB =  $vm_stp_status.UsedSpaceGB

            $regvm.UsedSpaceGB = $vm_strt_usedspaceGB

            $regvm.vmPathName = $vmPathName

            $regvm.Remarks = "Couldn't stop VM for re-registration process"

           }

         }

         

        $status_coll = $status_coll +  $regvm

        $vm_coll = $vm_coll + $vm_state

        

}

}

Write-Host "Vmware Registration Status" -BackgroundColor DarkCyan

$status_coll

Write-Host "Vmware Info details" -BackgroundColor DarkMagenta

$vm_coll

$reg_path = $ScriptDir + "\InventoryRegistration.csv"

$status_coll | Export-Csv -Path $reg_path -NoTypeInformation

$vmstatuspath = $ScriptDir + "\Vms_status.csv"

$vm_coll | Export-Csv -Path $vmstatuspath -NoTypeInformation

If( $flag -eq 0)

{

Write-Host "No VMs with Zero Byte found with PoweredON state"

}


Progressive Log file parsing for Windows servers- Powershell

 Clear-Host

######################################################

########File Configurations or Initialization#########

######################################################


#Update the path of the Log file. Not including the file name

#$logFilePath = "C:\Users\bobr\Desktop\LogFileParsing"

$logFilePath = "E:\APP_SERVERS\glassfish-4.1\glassfish4\glassfish\domains\walgreenmonet\logs"

#\\server1\glassfish-4.1\glassfish4\glassfish\domains\walgreenmonet\logs


#Update the Log File name with extension like server.log

$logFileName = "server.log"

$ParserFile = $logFilePath + "\" + $logFileName



$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path


#Create a pattern.txt file in the location where you have placed the script and

#add all the required unique pattern to line-by-line. It does simple match.

$patternFile = $ScriptDir + "\" + "pattern.txt"


# This file will be created automatically in the initial run and

# never modify this file content which is a numerical value to track file 

# line last read

$counterFile = $ScriptDir + "\" + "counterFile.log"


#File which you want to parse once it get archieved from the original source

#make sure you have a right pattern in place as it identified lastWriteTime to pick

$archivedFileNamePattern = "server.log_*"


# SMTP Relay server name

$smtp = "smtp.domain.com"


# E-mail to be sent to when the pattern matches with subject and body details

$from = "xyz@domain.com"

$to = "xyz@domain.com","abc@domain.com"

$subject = "Test Ignore: Walgreen: database connectivity issue server.log"

$body = "<B>This file contains the match found in accordance with pattern.txt file</B><BR>"


######################################################

###############End of Initialization###################

######################################################



$bodyContent = @()

$bodyContent = $bodyContent + $body 

$pattern = Get-Content $patternFile


#$pattern = @("SQLException","SQL")


If ( Test-Path $counterFile )

{

$lastLine = Get-Content -Path $counterFile

}

else

{

New-Item -Path $logFilePath -Name "counterFile.log" -ItemType File

New-Item -Path $logFilePath -Name "pattern.txt" -ItemType File

$count = Get-content $ParserFile | Measure-Object

$lastLine = $count.count

$lastLine|Out-File $counterFile

}

$newCount = Get-content $ParserFile | Measure-Object

$newLine = $newCount.Count

If ( $newLine -gt $lastLine )

{

$diff_Line = $newLine - $lastLine

#Write-Host "FromLineNum:$lastLine to ToLineNum:$newLine"

$matchedContent = Get-Content $ParserFile -Tail $diff_Line | Select-String -Pattern $pattern #-SimpleMatch

#Write-Host $matchedContent

$bodyContent = $bodyContent + $matchedContent

    $bodyAsString = $bodyContent | & {$ofs='<BR>';"$input"}

If ( $matchedContent )

{

#send e-mail

Send-MailMessage -From $from -To $to -Subject $subject -Body $bodyAsString -BodyAsHtml -SmtpServer $smtp

}

$lastLine = $newLine

$lastLine|Out-File $counterFile

}

ElseIF ( $newLine -lt $lastLine ) #check if a new file has been created and archiving older one with timestamp

{

#Read from the newly created file

$diff_Line = -1

#Write-Host "FromLineNum:0 to ToLineNum:$newLine"

$matchedContent = Get-Content $ParserFile -Tail $diff_Line | Select-String -Pattern $pattern #-SimpleMatch

#Write-Host $matchedContent

$bodyContent = $bodyContent + $matchedContent

# Get archived file lastline before overriding with newfile lastline

$archivedFileLastLine = $lastLine

$lastLine = $newLine

$lastLine|Out-File $counterFile

#Read the archived file to make sure we have read everything till the end of the file

#Get the archieved file name from recently modified date with a filename_*.log

$recentArchiveFileName = (Get-ChildItem -Path $logFilePath -Filter $archivedFileNamePattern |Sort-Object LastWriteTime | Select-Object -Last 1).FullName

$archievednewCount = Get-content $recentArchiveFileName | Measure-Object

$archievedNewLine = $archievednewCount.Count

if ( $archievedNewLine -gt $archivedFileLastLine )

{

$diff_Line = $archievedNewLine - $archivedFileLastLine

Write-Host "FromLineNum:$archivedFileLastLine to ToLineNum:$archievedNewLine"

$archievedMatchedContent = Get-Content $recentArchiveFileName -Tail $diff_Line | Select-String -Pattern $pattern #-SimpleMatch

#Write-Host $archievedMatchedContent

$bodyContent = $bodyContent + $archievedMatchedContent

$bodyAsString = $bodyContent | & {$ofs='<BR>';"$input"}

if ( $archievedMatchedContent )

{

#send e-mail

Send-MailMessage -From $from -To $to -Subject $subject -Body $bodyAsString -BodyAsHtml -SmtpServer $smtp

}

}

}

Friday, June 24, 2016

NRPE agent installation script for Linux

#!/bin/bash

OUTPUTFILE="/usr/local/nagios/libexec/tools/linux/nrpe-agent-installation.txt"

for server in `cat /usr/local/nagios/libexec/tools/serverlist.txt`

do

FLAG=0

for password in `cat /usr/local/nagios/libexec/tools/linux/password.txt`

do

/usr/local/nagios/libexec/tools/sftp_put.pl -h $server -u root -p $password -s "file" -f "/usr/local/nagios/libexec/tools/linux/test.txt" -t "/tmp/test.txt"

TEST=`echo $?`

if [ "$TEST" -eq "0" ];then

echo -e "$server \t $password" >> $OUTPUTFILE

#create nagios user

/usr/local/nagios/libexec/check_openssh.pl -H $server -u root -p $password -s command -C "useradd -m -d /var/spool/nagios -p "naZaxHcLCJwT2" nagios"

#Install NRPE Agent#

/usr/local/nagios/libexec/check_openssh.pl -H $server -u root -p $password -s command -C "yum -y install nagios-common-3.5.1-1.el6.x86_64 nagios-plugins-all-2.0.3-3.el6.x86_64 nagios-plugins-nrpe-2.15-7.el6.x86_64 nagios-nrpe-2.14-1.el6.rf.x86_64"

#Upload nrpe.cfg golden copy#

/usr/local/nagios/libexec/tools/sftp_put.pl -h $server -u root -p $password -s "file" -f "/usr/local/nagios/libexec/tools/linux/nrpe_cfg/nrpe.cfg" -t "/etc/nagios/nrpe.cfg"

#Upload nagios sudoers file#

/usr/local/nagios/libexec/tools/sftp_put.pl -h $server -u root -p $password -s "file" -f "/usr/local/nagios/libexec/tools/linux/nagios-sudo/nagios" -t "/etc/sudoers.d/nagios"

#Change the permissions of the nagios directories#

/usr/local/nagios/libexec/check_openssh.pl -H $server -u root -p $password -s command -C "chown -R nagios:nagios /etc/nagios/;chown -R nagios:nagios /usr/lib64/nagios/"

FLAG=1

break

fi

done

if [ "$FLAG" -eq "0" ];then

echo -e "$server \t No Password" >> $OUTPUTFILE

fi

done
#######################################
#Dependencies : 
#######################################

Friday, June 17, 2016

check_openssh.pl Plugin for Nagios

#!/usr/bin/perl
use Net::OpenSSH;
use Getopt::Long;
use Switch;
Getopt::Long::Configure('bundling');
$status=GetOptions
    (

     "H=s"   => \$dname, "DeviceName=s"     => \$dname,
     "u=s"   => \$uname, "UserName=s"    => \$uname,
     "p=s"   => \$password, "Password=s" => \$password,
     "w=s"   => \$warn,  "Warning=i" => \$warn,
     "c=s"   => \$crit, "Critical=i" => \$crit,
     "m=s"   => \$mount, "Mount=s"  => \$mount,
     "s=s"   => \$switch, "Switch=s" => \$switch,
     "C=s"   => \$command, "Command=s" => \$command
    );
        if ( $status == 0 ) {
        print_usage();
        }

#-- set up a new connection
# my $ssh = Net::OpenSSH->new('$uname:$password@$dname');
my $ssh = Net::OpenSSH->new($dname,user => $uname,password => $password);
$ssh->error and die "Connection error" . $ssh->error;

switch($switch)
{
case "command" {
                $ssh->system("$command");
                $ret = $ssh->error;
                $ret =~ s/\D//g;
                exit $ret;
                }
}
sub print_usage {
        print <
    Version:1.0

    Usage: check_openssh.pl -H host -u username -p password -w warn -c crit -m mode

 -H STRING or IPADDRESS
        Check interface on the indicated host.

 -u STRING VALUE
        Logon name of the remote UNIX server

 -p STRING VALUE
        Password to access the remote UNIX server

 -w INTEGER VALUE
        Warning condition depending on the Plug-in's used at remote server or Switch mode used

 -c INTEGER VALUE
        Critical condition depending on the Plug-in's used at remote server or Switch mode used
 -s STRING VALUE
        Switch mode is a string used to run the remote command or script
        memory  : memory usage
        check_load: Server Load
        check_disk: Disk Utilization on Server(provide mount point). e.g. -s check_disk -m /
        db_status : Check the health of Oracle DB server
        command : For running command at remote host. E.g. -s command -C "ls"
EOU

        exit 3;
}



Monday, May 30, 2016

Net::SFTP::Foreign - FTP protocol to put files from folder or file to remote server.

#!/usr/bin/perl
use Switch;
use Getopt::Long;
use Net::SFTP::Foreign;

#./sftp_put.pl -h hello.domainname.com -u root -p root123 -s "folder" -f "/usr/local/nagios/libexec/tools/linux/" -t "/usr/local/nagios/libexec/tools/linux/"

# ./sftp_put.pl -h hello.domainname.com -u root -p root123 -s "file" -f "/usr/local/nagios/etc/nrpe.cfg" -t "/usr/local/nagios/libexec/tools/linux/nrpe.cfg"

my $status = GetOptions(
        "host|h=s" => \$host,
        "username|u=s"  => \$username,
        "password|p=s"   => \$password,
        "from_dir|f=s"  => \$FROM_DIR,
        "to_dir|t=s"    => \$TO_DIR,
        "switch|s=s"    => \$fcopy,
);

if ( $status == 0 ) {
        print_usage();
        exit(3);
}

my $sftp;
$sftp = Net::SFTP::Foreign->new (
    $host,
    timeout         => 240,
    user            => $username,
    password        => $password,
    autodie         => 1,

);
switch ($fcopy)
{
case "folder"
{
$sftp->die_on_error("Unable to establish SFTP connection");
my $directory = $FROM_DIR;
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR))
{
next unless ($file =~ m/^[^\.]/);
my $TO_FILE = $TO_DIR.$file;
my $FROM_FILE = $FROM_DIR.$file;
#printf "To files:$TO_FILE\n";
#printf "From files:$FROM_FILE\n";
$sftp->rput($FROM_FILE ,$TO_FILE );
}
if($sftp->status)
{
print "Unsuccessfull filecopy copy to destination\n";
}
#$sftp->get("/usr/local/nagios/etc/nrpe.cfg","/usr/local/nagios/libexec/tools/linux/nrpe.cfg");
if($sftp->status)
{
print "Unsuccessfull filecopy from destination\n";
}

}
case "file"
{
my $TO_FILE = $TO_DIR.$file;
my $FROM_FILE = $FROM_DIR.$file;
$sftp->put($FROM_FILE ,$TO_FILE);
if($sftp->status)
{
print "Unsuccessfull filecopy to destination\n";
}
}

else {printf "check the option properly\n"}

}
$sftp->disconnect;
closedir(DIR);

sub print_usage {
        print <
Usage: sftp_put.pl -H host -u username -p password -s "file|folder" -f "from path" -t "to path"
Options:

    -H --host IPADDRESS
        Check interface on the indicated host.
    -u --username
        Provided the user name for the remote SFTP server, which has a privilage to read/write files
    -p --password
        Password for the remote SFTP server
    -f --from
       copy file/files from the location depending on the switch used
    -t --to
        put the file/files in this location depending on the switch used
    -s --switch
        it can be either one of file ot folder
EOU
}

Net::SFTP::Foreign - FTP protocol to get files from folder or file from remote server.

#!/usr/bin/perl
use Switch;
use Getopt::Long;
use Net::SFTP::Foreign;

#./sftp_get.pl -h hello.domainname.com -u root -p root123 -s "folder" -f "/usr/local/nagios/libexec/tools/linux/" -t "/usr/local/nagios/libexec/tools/linux/"
#./sftp_get.pl -h hello.domainname.com -u root -p root123 -s "file" -f "/usr/local/nagios/libexec/tools/linux/ran.txt" -t "/usr/local/nagios/libexec/tools/linux/ran.txt"

my $status = GetOptions(
        "host|h=s" => \$host,
        "username|u=s"  => \$username,
        "password|p=s"   => \$password,
        "from_dir|f=s"  => \$FROM_DIR,
        "to_dir|t=s"    => \$TO_DIR,
        "switch|s=s"    => \$fcopy,
);

if ( $status == 0 ) {
        print_usage();
        exit(3);
}

my $sftp;
$sftp = Net::SFTP::Foreign->new (
    $host,
    timeout         => 240,
    user            => $username,
    password        => $password,
    autodie         => 1,

);
switch ($fcopy)
{
case "folder"
{

$sftp->die_on_error("Unable to establish SFTP connection");
my $rlist = $sftp->ls("$TO_DIR",no_wanted => qr/^\./);
for (@$rlist)
{
#print "$_->{filename}\n";
my $FROM_FILE=$FROM_DIR.$_->{filename};
my $TO_FILE=$TO_DIR.$_->{filename};
#printf "From Files:$FROM_FILE \n";
#printf "To Files:$TO_FILE\n";
$sftp->get("$FROM_FILE","$TO_FILE");
}
if($sftp->status)
{
print "Unsuccessfull filecopy copy to destination\n";
}
}

case "file"
{
$sftp->get("$FROM_DIR","$TO_DIR");
}

else {printf "check the option properly\n"}

}

$sftp->disconnect;
closedir(DIR);



sub print_usage {
        print <Usage: sftp_get.pl -H host -u username -p password -s "file|folder" -f "from path" -t "to path"
Options:

    -H --host IPADDRESS
        Check interface on the indicated host.
    -u --username
        Provided the user name for the remote SFTP server, which has a privilage to read/write files
    -p --password
        Password for the remote SFTP server
    -f --from
       copy file/files from the location depending on the switch used
    -t --to
        put the file/files in this location depending on the switch used
    -s --switch
        it can be either one of file ot folder
EOU
}


Friday, May 6, 2016

MSSQL connection using ADODB connection and Recordset

'declare the variables
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL
'define the connection string, specify database driver
ConnString="DRIVER={SQL Server};SERVER=server01.domian.com;UID=service_account;" & _
PWD=P@ssw0rd;DATABASE=Database_name
'declare the SQL statement that will query the database
SQL = "Select * from table"

'create an instance of the ADO connection and recordset objects
Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
'Open the connection to the database
Connection.Open ConnString
'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection
Wscript.Echo "User" &VbTab& "AppName" &VbTab& "nDays"
'first of all determine whether there are any records
If Recordset.EOF Then
Wscript.Echo ("No records returned.")
Else
'if there are records then loop through the fields
Do While NOT Recordset.Eof  
Wscript.Echo Recordset.Fields(0) &VbTab& Recordset.Fields(1) &VbTab& Recordset.Fields(2)
'Wscript.Echo VbNewline   
Recordset.MoveNext
Loop
End If
'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing

Friday, December 11, 2015

DFS backlog powershell script using dfsrdiag.exe command

[CmdletBinding()]
Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$rgname,
  [Parameter(Mandatory=$True,Position=2)]
   [string]$rfname,
  [Parameter(Mandatory=$True,Position=3)]
   [string]$sendingmember,
  [Parameter(Mandatory=$True,Position=4)]
   [string]$receivingmember,
  [Parameter(Mandatory=$True,Position=5)]
   [int]$fcount
    )

#$content=dfsrdiag backlog /rgname:gmac /rfname:gmac /sendingmember:hsm-fs02 /receivingmember:evi-dfs-p1
$content=dfsrdiag backlog /rgname:$rgname /rfname:$rfname /sendingmember:$sendingmember /receivingmember:$receivingmember
$state1=$content | Select-String -pattern "No Backlog" -Quiet
#Write-Host $content
If ($state1)
{
Write-Host "OK:" $content"|count=0;0;"$fcount
exit (0)
}
Else
{
#$content = "Member <evi-dfs-p1> Backlog File Count: 2 Backlog File Names (first 2 files) 1. E:\Shares\Users\Paula.Norman\Archive 2014.pst 2. E:\Shares\Users\Paula.Norman\archive old pc.pst Operation Succeeded"
$state2=$content | Select-String -pattern "Backlog File Count: (\d+)" -Quiet
[int]$m=$content | Select-String -pattern "Backlog File Count: (\d+)" | ForEach-Object{$_.Matches[0].Groups[1].value}
#Write-Host "match" $m
If ($state2)
{
If ($m -ge $fcount)
{
Write-Host "CRITICAL:" $content"|count="$m";0;"$fcount
exit (2)
}
else
{
Write-Host "WARNING:" $content"|count="$m";0;"$fcount
exit(1)
}
}
}
Write-Host "UNKNOWN: $content Please check running command on the remote server manually|count="$m";0;"$fcount
exit(3)

Friday, October 30, 2015

ORACLE CLIENT installation

ORACLE CLIENT installation for check_oracle_health plugin on Linux x86_64 platform

1) INSTALL RPM PKGS
================
yum install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
check the installation path of the rpm to set the path for ORACLE HOME and LIBRARY PATH
rpm -ql oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm


2) SET ENV VARIABLES PERMANETLY
===========================
[root@RMIR1BLNNGOS01 libexec]# cat /etc/environment
ORACLE_HOME=/usr/lib/oracle/11.2/client64
LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib




3) CPAN
====
install DBI
install DBD::Oracle


4) VALIDATE THE CONNECTION


sqlplus 'test/test@123@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostIPaddress)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)))'
./check_oracle_health --username=test --password=test@123 --connect='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostIPaddress)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=service_name)))' --mode=tablespace-free

Thursday, April 23, 2015

Software installed on the servers using LDAP query to retrive server details-VBscript

on error resume next

 ' Determine DNS domain name from RootDSE object.
 Set objRootDSE = GetObject("LDAP://RootDSE")
 strDNSDomain = objRootDSE.Get("defaultNamingContext")
 'wscript.echo "defaultNamingContext (Domain Name System)" & strDNSDomain
 ' Use ADO to search Active Directory for all computers.
 Set adoCommand = CreateObject("ADODB.Command")
 Set adoConnection = CreateObject("ADODB.Connection")
 adoConnection.Provider = "ADsDSOObject"
 adoConnection.Open "ADs Provider"
 adoCommand.ActiveConnection = adoConnection


 ' Search entire domain.
 strBase = "<LDAP://" & strDNSDomain & ">"
 ' Filter on computer objects with server operating system.
 strFilter = "(&(objectCategory=computer)(operatingSystem=*server*))"
 ' Comma delimited list of attribute values to retrieve.
 strAttributes = "cn"
 ' Construct the LDAP syntax query.
 strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
 adoCommand.CommandText = strQuery
 'adoCommand.Properties("Page Size") = 100
 'adoCommand.Properties("Timeout") = 30
 'adoCommand.Properties("Cache Results") = False
 Set adoRecordset = adoCommand.Execute
 strComputerDN = Array()
 'arrSortOut = Array()
' cnsd = Array()
Dim cnsdstring
 counter = 0
 'step = 0
 count = 0
 ' Enumerate computer objects with server operating systems.
 Do Until adoRecordset.EOF
 ReDim Preserve strComputerDN(counter)
 strComputerDN(counter) = adoRecordset.Fields("cn").value
 Wscript.Echo "ServerName:" & strComputerDN(counter)

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
'strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"


Set objReg = GetObject("winmgmts://" & strComputerDN(counter) & _
 "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
  intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
   strEntry1a, strValue1)
  If intRet1 <> 0 Then
    objReg.GetStringValue HKLM, strKey & strSubkey, _
     strEntry1b, strValue1
  End If
  'WScript.Echo VbCrLf & "Service Display Name: "
  If strValue1 <> "" Then
    Wscript.Echo strValue1
  End If
  objReg.GetStringValue HKLM, strKey & strSubkey, _
   strEntry2, strValue2
  If strValue2 <> "" Then
    'WScript.Echo "Install Date: " & strValue2
  End If
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _
   strEntry3, intValue3
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _
   strEntry4, intValue4
  If intValue3 <> "" Then
     'WScript.Echo "Version: " & intValue3 & "." & intValue4
  End If
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _
   strEntry5, intValue5
  If intValue5 <> "" Then
    'WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes"
  End If
Next

 adoRecordset.MoveNext
 counter = counter + 1
 Loop
 'wscript.echo "defaultNamingContext" & strDNSDomain
 'wscript.echo counter


 'Clean up.
 adoRecordset.Close
 adoConnection.Close

Thursday, March 5, 2015

Citrix Desktop In Use

add-pssnapin Citrix.Broker.Admin.* -ErrorAction SilentlyContinue





clear



$DBG = Get-BrokerDesktopGroup | where {$_.Name -eq "IT" -and $_.Enabled -eq "True"}




#[Uint16] $TD

#[Uint16] $DIU


$TD = $DBG.TotalDesktops

$DIU = $DBG.DesktopsInUse

If ($TD -and $DIU -ne "null")



{

Write-Host "Desktop in Use:"$DIU"|DesktopsInUse="$DIU";0;$TD"



exit(0)

}

else


{

Write-Host "Unable to fetch the Get-BrokerDesktopGroup, please contact Chethan or Babu"



exit(2)

}


Cirtix Deskdtop Disconnected

add-pssnapin Citrix.Broker.Admin.* -ErrorAction SilentlyContinue





clear



$DBG = Get-BrokerDesktopGroup | where {$_.Name -eq "IT" -and $_.Enabled -eq "True"}




#[Uint16] $TD

#[Uint16] $DD


$TD = $DBG.TotalDesktops

$DD = $DBG.DesktopsDisconnected

If ($TD -and $DD -ne "null")



{

Write-Host "Desktops Disconnected:"$DD"|DesktopsDisconnected="$DD";0;$TD"



exit(0)

}

else


{

Write-Host "Unable to fetch the Get-BrokerDesktopGroup, please contact Chethan or Babu"



exit(2)

}