Skip to content

Instantly share code, notes, and snippets.

@DarkAllien
Created January 3, 2018 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkAllien/39a2d725cbed206af37d2a626cd87f1f to your computer and use it in GitHub Desktop.
Save DarkAllien/39a2d725cbed206af37d2a626cd87f1f to your computer and use it in GitHub Desktop.
Function Get-TSM_Content {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[Alias('SourceLocation')]
[String]$Source,
[Alias('PatternMatch')]
[String]$Pattern
)
$result = Select-String -Path $Source -pattern $Pattern
if ($result -match "REPL") {
$result = $result -notmatch "REPL"
}
return $result[0].ToString().Split(" ").Split(" ")[-1]
}
#cleaning WMI calss
Get-CimInstance -ClassName tivoli | Remove-CimInstance
#Creating WMI class with properties
$newClass = New-Object System.Management.ManagementClass ("root\cimv2", [String]::Empty, $null);
$newClass["__CLASS"] = "Tivoli";
$newClass.Qualifiers.Add("Static", $true)
$newClass.Properties.Add("TCPPORT", [System.Management.CimType]::String, $false)
$newClass.Properties["TCPPORT"].Qualifiers.Add("Key", $true)
$newClass.Properties.Add("TCPServeraddress", [System.Management.CimType]::String, $false)
$newClass.Properties["TCPServeraddress"].Qualifiers.Add("Key", $true)
$newClass.Properties.Add("Source", [System.Management.CimType]::String, $false)
$newClass.Properties["Source"].Qualifiers.Add("Key", $true)
$newClass.Properties.Add("Date", [System.Management.CimType]::Datetime, $false)
$newClass.Properties["Date"].Qualifiers.Add("Key", $true)
$newClass.Put()
#getting content
$Pattern1 = "TCPPORT"
$Pattern2 = "TCPSERVERADDR"
$date = (Get-Date)
#folders to look into
$Folders = 'C:\Program Files\Tivoli\TSM\baclient\', 'C:\Program Files\Tivoli\TSM\TDPSql'
$Folders = {$Folders}.invoke()
$Locations = @()
$Locations = {$Locations}.invoke()
$Sources = ''
$Sources = {$Sources}.invoke()
#drives to look into
$drives = Get-CimInstance –query "SELECT * from win32_logicaldisk where DriveType = 3" | Select-Object DeviceID
#building Sources array
ForEach ($Location in $drives) {
$Folders.add($Location.DeviceID + '\TSM\')
}
ForEach ($Folder in $Folders) {
if (Test-Path $Folder) {
$Locations.add($Folder)
}
}
ForEach ($Location in $Locations) {
if (Test-Path $Location) {
$Sources.add((Get-ChildItem -Path $Location -Filter "dsm*.opt").FullName)
}
}
#getting content from found files
ForEach ($Source in $Sources) {
if ($Source.Length -gt 0) {
foreach ($SourceFile in $Source) {
if ($SourceFile.Length -gt 0) {
if (Test-Path $SourceFile) {
$TCPPORT = Get-TSM_Content -SourceLocation $SourceFile -PatternMatch $Pattern1
$TCPServeraddress = Get-TSM_Content -SourceLocation $SourceFile -PatternMatch $Pattern2
New-CimInstance -ClassName Tivoli -Property @{TCPPORT = $TCPPORT; TCPServeraddress = $TCPServeraddress; Source = $SourceFile; Date = $date}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment