Add list-mysql-tables.ps1 and list-sql-tables.ps1

This commit is contained in:
Markus Fleschutz 2021-04-10 10:51:05 +02:00
parent d3e82db87a
commit 2536c282bb
4 changed files with 30 additions and 0 deletions

View File

@ -78,6 +78,7 @@ list-unused-files.ps1, lists unused files in a directory tree
list-cmdlets.ps1, lists the PowerShell cmdlets
list-earthquakes.ps1, lists earthquakes with magnitude >= 6.0 for the last 30 days
list-modules.ps1, lists the PowerShell modules
list-mysql-tables.ps1, lists the MySQL server tables
list-network-shares.ps1, lists the network shares of the local computer
list-news.ps1, lists the latest news
list-os-releases.ps1, lists OS releases and download URL
@ -88,6 +89,7 @@ list-random-passwords.ps1, prints a list of random passwords
list-random-pins.ps1, prints a list of random PIN's
list-scripts.ps1, lists all PowerShell scripts in this repository
list-services.ps1, lists the services on the local computer
list-sql-tables.ps1, lists the SQL server tables
list-system-info.ps1, lists system information on the local computer
list-tags.ps1, lists all tags in the current/given Git repository
list-tasks.ps1, lists all Windows scheduler tasks

1 Script Description
78 list-cmdlets.ps1 lists the PowerShell cmdlets
79 list-earthquakes.ps1 lists earthquakes with magnitude >= 6.0 for the last 30 days
80 list-modules.ps1 lists the PowerShell modules
81 list-mysql-tables.ps1 lists the MySQL server tables
82 list-network-shares.ps1 lists the network shares of the local computer
83 list-news.ps1 lists the latest news
84 list-os-releases.ps1 lists OS releases and download URL
89 list-random-pins.ps1 prints a list of random PIN's
90 list-scripts.ps1 lists all PowerShell scripts in this repository
91 list-services.ps1 lists the services on the local computer
92 list-sql-tables.ps1 lists the SQL server tables
93 list-system-info.ps1 lists system information on the local computer
94 list-tags.ps1 lists all tags in the current/given Git repository
95 list-tasks.ps1 lists all Windows scheduler tasks

View File

@ -159,10 +159,12 @@ Mega Collection of PowerShell Scripts
* [list-fritzbox-devices.ps1](Scripts/list-fritzbox-devices.ps1) - lists FRITZ!Box's known devices
* [list-logbook.ps1](Scripts/list-logbook.ps1) - lists the content of the logbook
* [list-earthquakes.ps1](Scripts/list-earthquakes.ps1) - lists earthquakes with magnitude >= 6.0 for the last 30 days
* [list-mysql-tables.ps1](Scripts/list-mysql-tables.ps1) - lists the MySQL server tables
* [list-news.ps1](Scripts/list-news.ps1) - lists the latest news
* [list-os-releases.ps1](Scripts/list-os-releases.ps1) - lists OS releases and download URL
* [list-random-passwords.ps1](Scripts/list-random-passwords.ps1) - prints a list of random passwords
* [list-random-pins.ps1](Scripts/list-random-pins.ps1) - prints a list of random PIN's
* [list-sql-tables.ps1](Scripts/list-sql-tables.ps1) - lists the SQL server tables
* [locate-city.ps1](Scripts/locate-city.ps1) - prints the geographic location of the given city
* [locate-ipaddress.ps1](Scripts/locate-ipaddress.ps1) - prints the geographic location of the given IP address
* [locate-zip-code.ps1](Scripts/locate-zip-code.ps1) - prints the geographic location of the given zip-code

View File

@ -0,0 +1,12 @@
# This script lists all of the tables in a MySQL database and exports the list as a CSV
# Install-Module InvokeQuery
# Run the above command if you do not have this module
param(
[Parameter(Mandatory=$true)]$server,
[Parameter(Mandatory=$true)]$database,
[Parameter(Mandatory=$true)]$dbuser,
[Parameter(Mandatory=$true)]$dbpass
)
$csvfilepath = "$PSScriptRoot\mysql_tables.csv"
$result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$dbuser; password=$dbpass; pooling = false; convert zero datetime=True" -Sql "SHOW TABLES" -CommandTimeout 10000
$result | Export-Csv $csvfilepath -NoTypeInformation

View File

@ -0,0 +1,14 @@
# This script lists all of the tables in a SQL Server database and exports the list as a CSV
# Install-Module InvokeQuery
# Run the above command if you do not have this module
param(
[Parameter(Mandatory=$true)]$server,
[Parameter(Mandatory=$true)]$database,
[Parameter(Mandatory=$true)]$username,
[Parameter(Mandatory=$true)]$password
)
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$csvfilepath = "$PSScriptRoot\sqlserver_tables.csv"
$result = Invoke-SqlServerQuery -Credential $creds -ConnectionTimeout 10000 -Database $database -Server $server -Sql "SELECT TABLE_NAME FROM $database.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" -CommandTimeout 10000
$result | Export-Csv $csvfilepath -NoTypeInformation