Skip to content

Instantly share code, notes, and snippets.

@VLoub
VLoub / SQL server - BYOK with AzureKeyVault - DeployIfNotExist.jsonc
Created September 25, 2025 13:29
Azure policy for creation of keyvault and key for SQL that need to be using CMK from its own keyvault. Just ensure that SQL server has private endpoint
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Sql/servers"
},
{
"value": "[subscription().displayName]",
"contains": "-Secret-"
@VLoub
VLoub / cetrificate-login-az-keyvault-from-linux.ps1
Last active October 8, 2024 17:19
How to use cert from key vault to login into Az Module azure management api from linux
# to download cert use
Connect-AzAccount -Identity # with acc that has access to Key Vault
# get token and download cert value
$vaultToken = Get-AzAccessToken -ResourceUrl 'https://vault.azure.net'
$headers = @{ Authorization = $($vaultToken.Type, $vaultToken.Token -join ' ') }
$targetTenantAppCert = Invoke-RestMethod -Method Get -Uri "https://$($env:YourKeyVault).vault.azure.net/secrets/EntraCert?api-version=7.1" -Headers $headers
# convert cert bytes to bytes with password as Connect-AzAccount needs to have password on it
$certBytes = [Convert]::FromBase64String($targetTenantAppCert.value)
$keyvaultCert = [Security.Cryptography.X509Certificates.X509Certificate2]::new($certBytes, $null, [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
@VLoub
VLoub / create timespan.ps1
Created March 12, 2024 13:40
Azure Duration to TimeSpan converter
$pramAssignment = @{
Name = [guid]::NewGuid().Guid
Scope = '/providers/Microsoft.Management/managementGroups/That Main Mgmt Group'
ExpirationDuration = [Xml.XmlConvert]::ToString($(New-TimeSpan -Days 4 -Hours 5)) # [Xml.XmlConvert]::ToTimeSpan('P4DT5H')
ExpirationType = 'AfterDuration'
PrincipalId = '5a4bds72-ab3e-4d8e-ab2f-8dd8917481a2'
RequestType = 'adminAssign'
RoleDefinitionId = '/providers/Microsoft.Authorization/roleDefinitions/8e3af653-a5ff-443c-a75c-2fe8c4bcb635'
ScheduleInfoStartDateTime = [DateTime]::UtcNow.ToString('o')
}
@VLoub
VLoub / function.ps1
Created February 22, 2024 11:28
Invoke-AzApplicationInsightsQuery
function Invoke-AzApplicationInsightsQuery {
[CmdletBinding()]
[Alias('iai')]
Param (
[Parameter(Mandatory,ValueFromPipelineByPropertyName,HelpMessage = 'Insights App ID get by (Get-AzApplicationInsights).AppId')]
[ValidateNotNullOrEmpty()]
[alias('Id')]
[Guid]$ApplicationId,
[Parameter(Mandatory,HelpMessage = 'Your KQL query')]
@VLoub
VLoub / Get-AzToken.ps1
Created February 5, 2024 14:13
Get Az Context token
# This PowerShell script first grabs the Azure context, fetches the profile client and requests an accesstoken.
# This entirely done using the Az.Profile module
$currentAzureContext = Get-AzContext
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient $azureRmProfile
$profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken
resource sqlServer_resource 'Microsoft.Sql/servers@2022-11-01-preview' = {
name: sqlServerName
location: location
identity: {
type: identity
userAssignedIdentities: ( contains(identity,'SystemAssigned') ) ? { '${replace(userDefinedIdentity,'"','')}': {} } : null
}
properties: {
administratorLogin: sqlServerAdministrator
administratorLoginPassword: sqlServerAdministratorPwd
choco install --whatif $(@(
'azure-cli'
'brave'
'calibre'
'chocolatey'
'ditto'
'git'
'github-desktop'
'irfanview'
'megasync'
@VLoub
VLoub / Veeam Agent dockerized on Oracle Linux 8 - Dockerfile
Last active March 6, 2023 12:27
Veeam Agent dockerized on Oracle Linux 8
FROM oraclelinux:8
# Configure systemd
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
/* https://blog.dotnetframework.org/2019/12/17/regular-expression-clr-udf-in-sql-server/ */
EXEC sp_changedbowner 'sa'
ALTER DATABASE RandomData SET trustworthy ON
GO
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO