Skip to content

Instantly share code, notes, and snippets.

View jpomfret's full-sized avatar

Jess Pomfret jpomfret

View GitHub Profile
@jpomfret
jpomfret / ExcelToSqlExample.ps1
Last active February 6, 2020 15:28
Imports a folder of Excel files into SQL folders
###########
## SETUP ##
###########
## get some data into xlsx files :)
$svr = Connect-DbaInstance -SqlInstance mssql1 -SqlCredential (Get-Credential)
foreach ($tbl in (Get-DbaDbTable -SqlInstance $svr -Database AdventureWorks2017 | where schema -eq 'sales' | select -first 10)){
Invoke-DbaQuery -SqlInstance $svr -Database AdventureWorks2017 -Query "Select top 10 * from $($tbl.Schema).$($tbl.name)" |
Export-Excel -Path "c:\temp\excel\$($tbl.name).xlsx" -ExcludeProperty ItemArray, RowError, RowState, Table, HasErrors
@jpomfret
jpomfret / ExcelToCsv.ps1
Created October 14, 2019 21:46
Read Excel Files in and Export CSVs
# Source for xlsx files
$SourceFolder = 'C:\Folder'
# Destination folder for where the csvs will go
$DestFolder = 'C:\Folder\csv'
# Foreach Excel file, read it in and then export to CSV with the same name.
Get-ChildItem $SourceFolder -Filter *.xlsx |
ForEach-Object { Import-Excel $_.FullName | Export-Csv -Path ("{0}\{1}.csv" -f $DestFolder, $_.basename) -NoTypeInformation }
# Source for xlsx files
$SourceFolder = 'C:\Folder'
# Destination folder for where the csvs will go
$DestFolder = 'C:\Folder\csv'
# Foreach Excel file, read it in and then export to CSV with the same name.
Get-ChildItem $SourceFolder -Filter *.xlsx |
ForEach-Object { Import-Excel $_.FullName | Export-Csv -Path ("{0}\{1}.csv" -f $DestFolder, $_.basename) -NoTypeInformation }
@jpomfret
jpomfret / DscSqlInstallWithMSA.ps1
Last active October 24, 2020 20:27
Sample configuration to install SQL Server using MSAs for Services
$SQLSvcMSA = 'DOMAIN\MSASQLName$'
$AgtSvcMSA = 'DOMAIN\MSAAgentName$'
# These are required but not used since we are using MSAs
$SQLSvcAccount = New-Object System.Management.Automation.PSCredential($SQLSvcMSA, $('mypassword' | ConvertTo-SecureString -asPlainText -Force))
$AgtSvcAccount = New-Object System.Management.Automation.PSCredential($AgtSvcMSA, $('mypassword' | ConvertTo-SecureString -asPlainText -Force))
Configuration ServerBuild {
Import-DscResource -ModuleName 'PSDscResources'
@jpomfret
jpomfret / versioninfo.ps1
Last active March 22, 2023 20:02
Get OS and SQL Version information with dbatools
$servers = Get-DbaRegServer -SqlInstance CmsServerName
$os = Get-DbaOperatingSystem -ComputerName $servers.name
$sql = Get-DbaProductKey -ComputerName $servers.name
$excelFile = C:\temp\VersionInfo.xlsx'
$osProps = 'ComputerName','Architecture','Version','Build','OSVersion', 'SPVersion', 'InstallDate','LastBootTime', 'ActivePowerPlan'
$sqlProps = 'ComputerName','InstanceName','SqlInstance','Version','Edition'
$osExcel = @{
@jpomfret
jpomfret / testingGist.ps1
Created February 17, 2018 12:33
Testing Gist
Import-Module dbatools
Get-DbaDatabase -SqlInstance Server1