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)

}


Citrix Desktop Available

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

$DD = $DBG.DesktopsDisconnected

$sobj = Get-BrokerDesktop | Where{$_.PowerState -eq "Off"}|Measure-Object -Line -Property PowerState | Select-Object Lines

$poweredoffdesktops = $sobj.Lines

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



{

$PAvail = ($TD-($DD+$DIU))

$Avail = $PAvail - $poweredoffdesktops

Write-Host "Total Desktop Available:"$Avail"|DesktopAvailble="$Avail";0;$TD"



exit(0)

}

else


{

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



exit(2)

}

 


Wednesday, February 11, 2015

Web Page Availability using VbScript via "MSXML2.ServerXMLHTTP" ntlm authentication

On Error Resume Next
aurl = Wscript.Arguments.Item(0)
url = Wscript.Arguments.Item(1)
apattern = Wscript.Arguments.Item(2)
pattern = Wscript.Arguments.Item(3)
ausername = Wscript.Arguments.Item(4)
username = Wscript.Arguments.Item(5)
apassword = Wscript.Arguments.Item(6)
password = Wscript.Arguments.Item(7)
If aurl = "-u" and apattern = "-m" and ausername = "-l" and apassword = "-p" Then
time1 = now()
'Wscript.Echo time1
Set HttpRequest = CreateObject("MSXML2.ServerXMLHTTP")
If Err.Number <> 0 Then
Wscript.Echo "UNKNOWN: Unhanlded Exception." &  Err.Description
Err.Clear
Wscritp.Quit(3)
Else
HttpRequest.open "POST", url, FALSE, username, password
HttpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HttpRequest.send ""
If Err.Number <> 0 Then
Wscript.Echo "UNKNOWN: Unhanlded Exception check the URL and the account." &  Err.Description
Err.Clear
Wscritp.Quit(2)
End If
time2 = now()
'Wscript.Echo time2
timex = DateDiff("s",time1,time2)
'Wscript.Echo HttpRequest.status
'Wscript.Echo HttpRequest.responseText
'Wscript.Echo timex
 If ( HttpRequest.status <> 200 ) then
 Wscript.Echo "CRITICAL: Error code:" & HttpRequest.status & "|seconds=" & timex & "s;0;60"
 Wscript.Quit(2)
 Set HttpRequest = Nothing
 Else
    Set myRegExp = New RegExp
    myRegExp.IgnoreCase = True
    myRegExp.Global = True
    myRegExp.Pattern = pattern
   'Wscript.Echo "errorPattern:" & errorPattern
   ' Echo for each match
    Set myMatches = myRegExp.Execute(HttpRequest.responseText)

    If myMatches.count > 0 Then
 Wscript.Echo "OK: match found and URL is accessable|seconds=" & timex & "s;0;60"
 Wscript.Quit(0)
 Set HttpRequest = Nothing
    Set myRegExp = Nothing
 Else
 Wscript.Echo "CRITICAL: match not found, though the URL is accessable|seconds=" & timex & "s;0;60"
 Wscript.Quit(2)
    Set HttpRequest = Nothing
    Set myRegExp = Nothing
 End If

 End If
End If
Else
Wscript.Echo "Help:"
Wscript.Echo "-u http://google.com"
Wscript.Echo "-m match-pattern"
Wscript.Echo "-l username"
Wscript.Echo "-p password"
Wscript.Echo ""
Wscript.Echo "UNKNOWN: Syntax error"
Wscript.Quit(3)
End If

Friday, January 9, 2015

Pull OS installed date on windows using VB Script


'Author : Babu Dhinakaran
'Date   : 9th Jan 2014
'Purpose : To pull OS Installed date on windows servers

Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
filename ="c:\system.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(filename, 1)

Do Until objTextFile.AtEndOfStream
  server = objTextFile.Readline
 
    Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
    For Each objItem in colItems
        dateTime.Value = objItem.InstallDate
        dateformat = dateTime.GetVarDate
    Next
Wscript.Echo server & vbTab  & dateformat & vbNewLine
Loop