﻿#
#
#
# This is PROPRIETARY SOURCE CODE of ARGSOFT TECHNOLOGY LIMITED.
#
# The contents of this file may not be disclosed to third parties, copied or
# duplicated in any form, in whole or in part, without the prior written
# permission of ARGSOFT TECHNOLOGY LIMITED.
#
# RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
# and Computer Software clause at DFARS 252.227-7013, and/or in similar or
# successor clauses in the FAR, DOD or NASA FAR Supplement.
#
# Unpublished - rights reserved under the Copyright Laws of the United States
# and other countries.

#******************************************************************************************************
#
# Customize SQL Server, database and export directory
#
#******************************************************************************************************

$server = "NUC34\SQLExpress"
$database = "ArgentAT"

$exportDir = "C:\TEMP"


$connectionTemplate = "Data Source={0};Integrated Security=SSPI;Initial Catalog={1};"
$connectionString = [string]::Format($connectionTemplate, $server, $database)
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString

$command = New-Object System.Data.SqlClient.SqlCommand
$command.CommandText = @"
SELECT T.NAME, T.TARGET_SITE, M.FROM_DATETIME, M.TO_DATETIME, (SELECT NAME FROM ARGSOFT_AAC_ADVSCALENDAR WHERE '{' + UUID + '}' = M.CALENDAR) AS CALENDAR, M.ADHOC 
FROM [dbo].[ARGSOFT_AD_TARGETSITE] T JOIN [dbo].[ARGSOFT_AD_MAINTENANCE] M 
ON T.UUID = M.PUUID 
ORDER BY T.NAME, M.RANK
"@
$command.Connection = $connection

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $command
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$connection.Close()

$csv = Join-Path $exportDir "ARGENT_SENTINEL_MAINTENANCE.csv"
	
$DataSet.Tables[0]  | Export-Csv $csv -NoTypeInformation

Write-Host $extractFile

Write-Host "Successfully export data of Argent Sentinel Maintenance Schedule to file:" $csv


