Once again I am stumped on a script and require the assistance of the wonderful [H] members.
I am writing a Powershell script that enables me to backup my event logs to a SQL database. I need a way to make sure I only input unique events into the database. Here is what I have come up with:
$Result will be put into the following line:
When I output $Result I get the following:
So, here is where I need the help. Is there a way to pull out the value of LastIndex, in this case 20, as a string?
I am writing a Powershell script that enables me to backup my event logs to a SQL database. I need a way to make sure I only input unique events into the database. Here is what I have come up with:
Code:
function RunQuery($SqlQuery) {
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
$SqlCmd = New-Object System.Data.SQLClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0]
$SQLConnection.Close()
}
$Machine = Some Machine
$Result = RunQuery("SELECT LastIndex FROM Poll WHERE Machine = '$Machine'")
$Result will be put into the following line:
Code:
$AppLog = Get-EventLog -LogName "Application" -ComputerName "Master" | where {$_.Index -GT "$Result"}
When I output $Result I get the following:
Code:
1
LastIndex
---------
20
So, here is where I need the help. Is there a way to pull out the value of LastIndex, in this case 20, as a string?