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)

}


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)

}