mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-02 10:59:14 +01:00
Add list-mysql-tables.ps1 and list-sql-tables.ps1
This commit is contained in:
parent
d3e82db87a
commit
2536c282bb
@ -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
|
||||
|
|
@ -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
|
||||
|
12
Scripts/list-mysql-tables.ps1
Normal file
12
Scripts/list-mysql-tables.ps1
Normal 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
|
14
Scripts/list-sql-tables.ps1
Normal file
14
Scripts/list-sql-tables.ps1
Normal 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
|
Loading…
Reference in New Issue
Block a user