Sunday, May 5, 2019

Add a calculated property with Select-Object in PowerShell

https://4sysops.com/archives/add-a-calculated-property-with-select-object-in-powershell

Get List of Files and Insert to SQL Server Table

Get-ChildItem -Path C:\ETL\EXPORT_FILES |
Select-Object Name, FullName, Extension, CreationTime, Length |
Write-SqlTableData -ServerInstance localhost -DatabaseName ETL -SchemaName import -TableName ImportFileList -Force

Initially loclhost was working but then it stopped with failed to connect message; changed to actual SQL Server instance name
and that worked:


Get-ChildItem -Path C:\ETL\EXPORT_FILES |
Select-Object Name, FullName, Extension, CreationTime, Length |
Write-SqlTableData -ServerInstance "DESKTOP-U8PAEJC" -DatabaseName "DEV_STAGING" -SchemaName "import" -TableName "ImportFileList" -Force

Get List of Files in Folder and Pipe to Excel

Get-ChildItem -Path C:\ETL\EXPORT_FILES |
Select-Object Name, FullName, Extension, CreationTime, Length |
Export-Excel -Now

Import Excel to SQL Server Table

Import-Excel -Path C:\ETL\EXCEL-FILES\CONTACT.xlsx |
Write-SqlTableData -ServerInstance localhost -DatabaseName ETL -SchemaName import -TableName Contact -Force
 
 
-Force on Write-SqlTableData will create anything that doesn't exist; e.g. Databasename, SchemaName, TableName
 
 
Column types will be nvarchar(max)


Saturday, May 4, 2019

Using Version Control in VS Code

https://code.visualstudio.com/docs/editor/versioncontrol

Use PowerShell 6 in VS Code

VSCode as a console for PowerShell Core 6 - Use Multiple shells

https://4sysops.com/archives/vscode-as-a-console-for-powershell-core-6-part-1-multiple-shells/

PowerShell Invoke-SQLCmd outputs DataTables you can INSERT into SQL Server

https://www.mssqltips.com/sqlservertip/5802/powershell-module-to-read-directory-contents-and-store-in-a-sql-server-table/

Process file paths from the pipeline in PowerShell functions

https://4sysops.com/archives/process-file-paths-from-the-pipeline-in-powershell-functions/

Tips on Implementing Pipeline Support

https://learn-powershell.net/2013/05/07/tips-on-implementing-pipeline-support/

Understanding PowerShell pipeline parameter binding

https://4sysops.com/archives/understanding-powershell-pipeline-parameter-binding/

Understanding the PowerShell $_ and $PSItem pipeline variables

https://4sysops.com/archives/understanding-the-powershell-_-and-psitem-pipeline-variables/

The PowerShell Here-String – Preserve text formatting

https://4sysops.com/archives/the-powershell-here-string-preserve-text-formatting/

Thursday, May 2, 2019

PowerShell Tips on MSSQLTips.com

https://www.mssqltips.com/sql-server-tip-category/81/powershell/

PowerShell Module to Read Directory Contents and Store in a SQL Server Table

https://www.mssqltips.com/sqlservertip/5802/powershell-module-to-read-directory-contents-and-store-in-a-sql-server-table/

Getting Started with PowerShell File Properties and Methods

https://www.mssqltips.com/sqlservertip/5878/getting-started-with-powershell-file-properties-and-methods/

Rename and Move a File

https://www.mssqltips.com/sqlservertip/3207/rename-and-move-a-file-with-powershell-in-a-sql-server-agent-job/

Strings in PowerShell

https://mcpmag.com/articles/2015/07/23/strings-in-powershell.aspx

Note "HERE" string

@"
string content goes here; can be multiple line; can include variables; e.g. $varname
"@

Another way of evaluating a string within a string"

$MyName = "State Your Name"

  "Hello $($MyName), today is $((Get-Date).DayOfWeek)"