I need a PowerShell script to sync between an Azure SQL Database and a SQL Server on-premises database. I have gone through this link (https://learn.microsoft.com/en-us/azure/azure-sql/database/scripts/sql-data-sync-sync-data-between-azure-onprem) and I was able to generate Sync Agent, Sync Group, Sync member. Now I'm getting an error like below:
the powershell code is as below
using namespace Microsoft.Azure.Commands.Sql.DataSync.Model
using namespace System.Collections.Generic
Write-Host "Adding tables and columns to the sync schema..."
$databaseSchema = Get-AzSqlSyncSchema -ResourceGroupName "myresource" -ServerName "myservername" `
-DatabaseName "mydatabase" -SyncGroupName "TestSync" `
$databaseSchema | ConvertTo-Json -depth 5 -Compress | Out-File "syncSchema.json"
$newSchema = [AzureSqlSyncGroupModel]::new()
$newSchema.Tables = [List[AzureSqlSyncGroupSchemaTableModel]]::new();
Related
I am trying create Log Analytics query based Alert Rule using powershell script and command :- New-AzScheduledQueryRule .
Here I am trying to declare a variable called $ResourceGroup and $SubscriptionID in powershell script and want to use this in Log analytics query, so i can call script and pass arguments of Resource Group and subscription and Log Alert Query Rule will be created for scope of ResourceGroup . But when I try to deploy the Log query Alert Rule , the variables are not recognized inside query.
`$query='AzureMetrics
| where ResourceId has "Microsoft.Network/azureFirewalls"
| where MetricName=="FirewallHealth"
| where Maximum <100
| project FirewallHealth=toint(Maximum),Resource, ResourceGroup'
$source = New-AzScheduledQueryRuleSource -Query $query -DataSourceId "/subscriptions/$SubscriptionIDWS/resourcegroups/$ResourceGroupWS/providers/microsoft.operationalinsights/workspaces/$LogAnalyticsWSName" -QueryType ResultCount
New-AzScheduledQueryRule -ResourceGroupName $ResourceGroupLAWorkspace -Location "eastus" -Action $alertingAction -Enabled $true -Description $($AlertDescription) -Schedule $schedule -Source $source -Name $($AlertName)
After create a runbook and edit content, I want to create variable and set value for them. How can I do it by ansible or azure cli ?
Please help me
Azure Automation stores each encrypted variable securely. When you create a variable, you can specify its encryption and storage by Azure Automation as a secure asset.
You must set the value with the Set-AzAutomationVariable cmdlet or the internal Set-AutomationVariable cmdlet. You use the Set-AutomationVariable in your runbooks that are intended to run in the Azure sandbox environment, or on a Windows Hybrid Runbook Worker.
You can create variables and set value for them using PowerShell script.
$rgName = "ResourceGroup01"
$accountName = "MyAutomationAccount"
$vm = Get-AzVM -ResourceGroupName "ResourceGroup01" -Name "VM01" | Select Name, Location,Extensions
New-AzAutomationVariable -ResourceGroupName "ResourceGroup01" -AutomationAccountName "MyAutomationAccount" -Name "MyComplexVariable" -Encrypted $false -Value $vm
$vmValue = Get-AzAutomationVariable -ResourceGroupName "ResourceGroup01" -AutomationAccountName "MyAutomationAccount" -Name "MyComplexVariable"
$vmName = $vmValue.Value.Name
$vmTags = $vmValue.Value.Tags
Reference: Manage variables in Azure Automation | Microsoft Docs
I have prepared simple powershell script for creating Log Analytics computer group. Based on that group I want to add VMs to the Update Management solution in Azure. Command presented below. For now I can add few VMs using this structure 'Heartbeat | where (Computer == "vmA" or Computer == "vmB")'. This approach is good for few VMs, question is what can I do with a list of 50 or more VMs? Is there any way to pass variable/param to this -Query?
New-AzOperationalInsightsComputerGroup `
-ResourceGroupName "testRG" `
-WorkspaceName "Testloganalytics" `
-SavedSearchId "testID01" `
-DisplayName "GroupName" `
-Category "Updates" `
-Query 'Heartbeat | where (Computer == "vmA" or Computer == "vmB")' `
-Version 1 `
-Force
You can specify a variable which contains all the vms like this:
$myvms = '("vm1","vm2","vm3","vm4","vm5")'
then, for the -Query, you can use the in operator, the command like below:
-Query "Heartbeat | where Computer in $myvms"
I have powershell cmdlets that output either a list or formatted as table.
I would like to stream the output to an azure table storage to be accessed by Power BI.
Is this possible?
Thanks
When working with Azure Storage Tables you don't have any way to directly stream to them but you can write data row by row.
Writing to a table is done like this
# Get the necessary modules, if needed. Latter one was not installed for me by running
# the top command.
# Install-Module AzureRM
# Install-Module AzureRMStorageTable
# Login to Azure RM model
Login-AzureRmAccount
# Some variables
$storageAccountName = <account name>
$tableName = <table name>
$partitionKey1 = <partition name
$rg = <resource group name>
# Get the storage account and its context
$storageAccount = Get-AzureRmStorageAccount -ResourceGroupName $rg `
-Name $storageAccountName
$ctx = $storageAccount.Context
# Create a new table, if needed
# New-AzureStorageTable –Name $tableName –Context $ctx
# Get a reference to the table
$storageTable = Get-AzureStorageTable –Name $tableName –Context $ctx
# Add some rows into the table
Add-StorageTableRow `
-table $storageTable `
-partitionKey $partitionKey1 `
-rowKey ("CA") -property #{"username"="Chris";"userid"=1}
See this page for more detailed information on how to work with Azure Storage Tables using PowerShell.
I have a script that installs OMS extensions to all ARM VMs in the subscription. The problem is that I have subscriptions that contain only ARM VMs, subscriptions that contain only Classic VMs, and subscription that have both types of VMs. How can I modify the script to work in all of the conditions? The script is:
#This script installs OMS Monitoring Agent to all VMs in the selected Subscription.
#Before running this script, the user must login to Azure account and select target subscription.
#Example:
#Login-AzureRmAccount
#Select-AzureRmSubscription 'SubscriptionName'
$WorkspaceID = 'Provide Workspace ID here'
$WorkspaceKey = 'Provide Workspace key here'
$VMs = Get-AzureRmVM
$VMs.where({$_.osprofile.windowsconfiguration}) | ForEach-Object {
"Installing Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent Extension: {0}" -f $_.id
Set-AzureRmVMExtension -ResourceGroupName $_.ResourceGroupName -VMName $_.Name -Name omsAgent -Publisher 'Microsoft.EnterpriseCloud.Monitoring' `
-ExtensionType 'MicrosoftMonitoringAgent' -AsJob -TypeHandlerVersion '1.0' -Location $_.Location -ForceRerun 'yesh' `
-SettingString ( "{'workspaceId': '$WorkspaceID'}") `
-ProtectedSettingString "{'workspaceKey': '$WorkspaceKey'}" |
Add-Member -Name VM -Value $_.Id -MemberType NoteProperty
}
Since you got both classic and ARM VMs, you got two different deployment models, hence two different PowerShell modules you are using.
In other words, you need to log in separately for each and have separate scripts for using them.
In the classic model you need to run the following cmdlet to login and access your VMs:
Add-AzureAccount
Get-AzureVM | Set-AzureVMExtension ``
-Publisher 'Microsoft.EnterpriseCloud.Monitoring' ``
-ExtensionName 'MicrosoftMonitoringAgent' ``
-Version '1.*' ``
-PublicConfiguration "<workspace id>" ``
-PrivateConfiguration "<workspace key>" ``
While searching for information I found this script. It's a script for on-boarding VMs from single, or multiple subscriptions, using both deployment models.