Skip to content

Instantly share code, notes, and snippets.

@MartinMiles
Created March 12, 2023 02:58
Show Gist options
  • Save MartinMiles/401773c36f8c1f4d58f53799e8d0ff9a to your computer and use it in GitHub Desktop.
Save MartinMiles/401773c36f8c1f4d58f53799e8d0ff9a to your computer and use it in GitHub Desktop.
SPE snipped to return items from MASTER database of my XM Cloud instance
$sql = @"
USE [{0}]
SELECT ID, [Name], [TemplateID], Created from [dbo].[Items]
"@
Import-Function Invoke-SqlCommand
Write-Verbose "Cleaning up the History, EventQueue, and PublishQueue tables in the $($db.Name) database."
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder $connection
$dbName = $builder.InitialCatalog
$query = [string]::Format($sql, $dbName)
Invoke-SqlCommand -Connection $connection -Query $query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment