Aggiunta elenco oggetti
This commit is contained in:
parent
d355d6b813
commit
3bd9fcf810
49
script/elenco_oggetti.ps1
Normal file
49
script/elenco_oggetti.ps1
Normal file
@ -0,0 +1,49 @@
|
||||
# Script per elencare gli oggetti del database
|
||||
# Importa la configurazione
|
||||
. $PSScriptRoot\conf.ps1
|
||||
|
||||
# Importa il modulo SQL Server se non è già caricato
|
||||
if (-not (Get-Module -Name SQLPS)) {
|
||||
Import-Module SQLPS -DisableNameChecking
|
||||
}
|
||||
|
||||
try {
|
||||
# Query per ottenere l'elenco degli oggetti
|
||||
$query = @"
|
||||
SELECT
|
||||
CASE type
|
||||
WHEN 'U' THEN 'Table'
|
||||
WHEN 'V' THEN 'View'
|
||||
WHEN 'P' THEN 'Stored Procedure'
|
||||
WHEN 'FN' THEN 'Function'
|
||||
WHEN 'TR' THEN 'Trigger'
|
||||
ELSE type
|
||||
END AS ObjectType,
|
||||
SCHEMA_NAME(schema_id) AS SchemaName,
|
||||
name AS ObjectName
|
||||
FROM sys.objects
|
||||
WHERE type IN ('U', 'V', 'P', 'FN', 'TR')
|
||||
ORDER BY ObjectType, SchemaName, ObjectName
|
||||
"@
|
||||
|
||||
# Esegui la query e salva i risultati
|
||||
$results = Invoke-Sqlcmd -ServerInstance $config.DbHostInput -Database $config.DbName -Username $config.DbUser -Password $config.DbPassword -Query $query
|
||||
|
||||
# Prepara l'output
|
||||
$output = "Elenco oggetti del database $($config.DbName) su $($config.DbHostInput) il $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`r`n"
|
||||
$output += "Tipo;Schema;Nome`r`n"
|
||||
|
||||
# Formatta e aggiungi ogni oggetto all'output
|
||||
foreach ($row in $results) {
|
||||
$output += "$($row.ObjectType);$($row.SchemaName);$($row.ObjectName)`r`n"
|
||||
}
|
||||
|
||||
# Scrivi il risultato su file
|
||||
$output | Out-File -FilePath (Join-Path -Path $config.LogDir -ChildPath "_elenco_oggetti.csv") -Encoding UTF8
|
||||
|
||||
Write-Host "Elenco oggetti salvato correttamente in _elenco_oggetti.csv"
|
||||
}
|
||||
catch {
|
||||
Write-Error "Si è verificato un errore: $_"
|
||||
exit 1
|
||||
}
|
3687
sql/storedTestbes/_elenco_oggetti.csv
Normal file
3687
sql/storedTestbes/_elenco_oggetti.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user