mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-17 02:01:01 +01:00
Add convert-mysql2csv.ps1
This commit is contained in:
parent
99197dfc29
commit
a73e6d9885
@ -27,6 +27,7 @@ close-thunderbird.ps1, closes Mozilla Thunderbird gracefully
|
|||||||
close-vlc.ps1, closes the VLC media player gracefully
|
close-vlc.ps1, closes the VLC media player gracefully
|
||||||
close-windows-terminal.ps1, closes Windows Terminal gracefully
|
close-windows-terminal.ps1, closes Windows Terminal gracefully
|
||||||
configure-git.ps1, sets up the Git user configuration
|
configure-git.ps1, sets up the Git user configuration
|
||||||
|
convert-mysql2csv.ps1, converts the MySQL database table to a CSV file
|
||||||
create-branch.ps1, creates a new branch in the current/given Git repository
|
create-branch.ps1, creates a new branch in the current/given Git repository
|
||||||
create-shortcut.ps1, creates a shortcut
|
create-shortcut.ps1, creates a shortcut
|
||||||
create-symlink.ps1, creates a symbolic link
|
create-symlink.ps1, creates a symbolic link
|
||||||
|
|
@ -148,6 +148,7 @@ Mega Collection of PowerShell Scripts
|
|||||||
* [check-ipv4-address.ps1](Scripts/check-ipv4-address.ps1) - checks the given IPv4 address for validity
|
* [check-ipv4-address.ps1](Scripts/check-ipv4-address.ps1) - checks the given IPv4 address for validity
|
||||||
* [check-ipv6-address.ps1](Scripts/check-ipv6-address.ps1) - checks the given IPv6 address for validity
|
* [check-ipv6-address.ps1](Scripts/check-ipv6-address.ps1) - checks the given IPv6 address for validity
|
||||||
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
|
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
|
||||||
|
* [convert-mysql2csv.ps1](Scripts/convert-mysql2csv.ps1) - converts the MySQL database table to a CSV file
|
||||||
* [csv-to-text.ps1](Scripts/csv-to-text.ps1) - converts the given CSV file into a text list
|
* [csv-to-text.ps1](Scripts/csv-to-text.ps1) - converts the given CSV file into a text list
|
||||||
* [display-time.ps1](Scripts/display-time.ps1) - displays the current time for 10 seconds by default
|
* [display-time.ps1](Scripts/display-time.ps1) - displays the current time for 10 seconds by default
|
||||||
* [generate-qrcode.ps1](Scripts/generate-qrcode.ps1) - generates a QR code
|
* [generate-qrcode.ps1](Scripts/generate-qrcode.ps1) - generates a QR code
|
||||||
|
40
Scripts/convert-mysql2csv.ps1
Normal file
40
Scripts/convert-mysql2csv.ps1
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/pwsh
|
||||||
|
<#
|
||||||
|
.SYNTAX convert-mysql2csv.ps1 [<server>] [<database>] [<DBuser>] [<DBpassword>] [<query>]
|
||||||
|
.DESCRIPTION convert the MySQL database table to a CSV file
|
||||||
|
.LINK https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
$server,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
$database,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
$dbuser,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
$dbpass,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
$query
|
||||||
|
)
|
||||||
|
if (($server -eq "") -or ($server -eq $null)) {
|
||||||
|
Write-Host "Please specify a server"
|
||||||
|
}
|
||||||
|
elif (($database -eq "") -or ($database -eq $null)) {
|
||||||
|
Write-Host "Please specify a database"
|
||||||
|
}
|
||||||
|
elif (($dbuser -eq "") -or ($dbuser -eq $null)) {
|
||||||
|
Write-Host "Please specify a database user"
|
||||||
|
}
|
||||||
|
elif (($dbpass -eq "") -or ($dbpass -eq $null)) {
|
||||||
|
Write-Host "Please specify a database user password"
|
||||||
|
}
|
||||||
|
elif (($query -eq "") -or ($query -eq $null)) {
|
||||||
|
Write-Host "Please specify a query"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$csvfilepath = "$PSScriptRoot\mysql_table.csv"
|
||||||
|
$result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$dbuser; password=$dbpass; pooling = false; convert zero datetime=True" -Sql $query -CommandTimeout 10000
|
||||||
|
$result | Export-Csv $csvfilepath -NoTypeInformation
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user