John Liu Blog

Every drop counts

Create embeddings in SQL2025

SQL2025 has the ability to use local ONNX model on the server to create embeddings. Following are steps for configuration. 1. If this feature is still developer preview feature, run following SQL scrit to enable preview features ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON; 2. Enable AI runtime on SQL2025 EXEC sp_execute 'external AI runtime enabled',1; RECONFIGURE WITH OVERRIDE; 3. Set up the ONNX runtime library Create a local folder, say C:\onnx_runtime, to store the runtime libarary files.

PowerShell File Format Conversion

PowerShell has function to convert files between different formats. To convert Json to CSV: $procs = Get-Content -Path c:\temp\test.json | ConvertFrom-Json $procs | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | Out-File c:\temp\test.csv If the Json is nested $procs = Get-Content -Path c:\temp\test.json | ConvertFrom-Json $procs.Table1 | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | Out-File c:\temp\Table1.csv $procs.Table2 | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | Out-File c:\temp\Table2.csv

PowerShell script to update hosts file

You may need to add computer entery into hosts file for easy RDP access. Run following PowerShell script in administrator mode to add the target machine/IP into hosts file. Or you can manually open the C:\Windows\System32\drivers\etc\hosts file and edit it. #Run this script in Administrator mode cls $Srv = Read-Host -Prompt "Target Server Name" $IP = Read-Host -Prompt "Target Server IP" $newEntry =$IP + " " + $Srv $hostfile = Get-Content C:\Windows\System32\drivers\etc\hosts [bool]$Update = 0 if (-NOT ($IP | Select-String -Pattern "[0-9]+\.

PowerShell export data to file

This example PowerShell script exports data from SQL table into files and then zip them together. Clear-Host function ExportDataToFile { param( [string]$instancename, [string]$dbname, [string]$flowname, [string]$clientname, [string]$filepath ) $guid = @() $guid_replace = @() if ([string]::IsNullOrEmpty($filepath)) { throw "filepath is rquired but not specified!" } if ($filepath -match "\\$") { $filepath = $filepath.Substring(0,$filepath.Length-1) } #connection to SQL $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server=" + $instancename + ";Database=" + $dbname + ";Integrated Security=True" $SqlCmd = New-Object System.

Azure sign-in methods in PowerShell script

When using PowerShell script to run tasks in Azure environment, we need first to sign-in to Azure. There are several ways to sign-in to Azure in PowerShell script. 1. Interactive sign-in we can using either Connect-AzAccount or Login-AzAccount -Credential (Get-Credential) Login-AzAccount and Add-AzAccount are alias of Connect-AzAccount. With -Credential (Get-Credential) option, it let you interactively enter the credential on the cmd interface, otherwise, it popup a GUI to let you login.