Skip to content

Instantly share code, notes, and snippets.

View roberto-mardeni's full-sized avatar

Roberto Mardeni roberto-mardeni

View GitHub Profile
@roberto-mardeni
roberto-mardeni / azure-virtual-machine-power-state.cs
Created July 14, 2022 15:09
Get Azure Virtual Machine Power State with Azure SDK for .Net - CSHARP
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute.Models;
static async Task GetVirtualMachinesPowerStateAsync(string resourceGroupName, string virtualMachineName)
{
ArmClient client = new ArmClient(new DefaultAzureCredential());
SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();
@roberto-mardeni
roberto-mardeni / azure-virtual-machine-statuses.cs
Created July 14, 2022 14:48
Get Azure Virtual Machine Status using Azure .Net SDK - CSHARP
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute.Models;
// Code omitted for brevity
ArmClient client = new ArmClient(new DefaultAzureCredential());
string resourceGroupName = "vsonvm";
SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();
@roberto-mardeni
roberto-mardeni / call-azure-function-with-aad-client-credential-flow.ps1
Created June 24, 2022 14:25
Demonstrates how to execute an Azure Function that has Azure Active Directory Authentication enabled.
$ClientId = "== INSERT CLIENT ID =="
$ClientSecret = "== INSERT CLIENT SECRET =="
$TenantId = "== INSERT TENANT ID =="
$AppId = "== INSERT APP ID =="
$functionUri = "https://myfunctionXYZ.azurewebsites.net"
$functionName = "HttpTrigger1"
$authBody = @{
"tenant" = $TenantId
"client_id" = $ClientId
@roberto-mardeni
roberto-mardeni / AzureAppInsightsTips.md
Last active June 9, 2022 14:32
Azure Application Insights Tips

SQL Depency Tracking not working

  • Nuget packages recommended versions:
    • System.Diagnostics.DiagnosticSource v6.0.0+
    • Microsoft.ApplicationInsights v2.20.0+
  • Microsoft.Data.SqlClient v4+
@roberto-mardeni
roberto-mardeni / Find-AzResourceByTags.ps1
Created September 24, 2021 19:11
Find all Azure Resources that include all tags given
<#
.SYNOPSIS
Find Azure Resources with all the given tags
.DESCRIPTION
Will query for all resources using the given tags and return only those that have all tags specified
Will return all resources found
.PARAMETER Tags
A hashtable of key/value pairs of the tags to query for
@roberto-mardeni
roberto-mardeni / New-FileOfSize.ps1
Created August 30, 2021 18:55
Create file of size with PowerShell
param($filename="test.dat",$size="1MB")
$f = New-Object System.IO.FileStream $filename, Create, ReadWrite
$f.SetLength($size)
$f.Close()
@roberto-mardeni
roberto-mardeni / web.config
Created September 4, 2020 13:49
Azure Cache for Redis Configuration Sample
<configuration>
<appSettings>
<add key="RedisConnectionString" value="<name>.redis.cache.windows.net:6380,password=<key>,ssl=True,abortConnect=False" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<sessionState mode="Custom" customProvider="RedisStateStore">
<providers>
<add name="RedisStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="RedisConnectionString" />
@roberto-mardeni
roberto-mardeni / selenium.aci.yaml
Created July 7, 2020 14:22
Selenium on Azure Container Instances Sample
apiVersion: 2018-10-01
location: eastus
name: selenium
properties:
containers:
- name: selenium-hub
properties:
environmentVariables:
- name: 'JAVA_TOOL_OPTIONS'
value: '-Xmx800m'
# Configure Firewall
ufw allow from any to any port 1433 proto tcp
ufw allow from any to any port 135 proto tcp
ufw allow from any to any port 51000 proto tcp
# Configure Port Routing
ip=$(curl ifconfig.me)
iptables -t nat -A PREROUTING -d $ip -p tcp --dport 135 -m addrtype --dst-type LOCAL -j DNAT --to-destination $ip:13500 -m comment --comment RpcEndPointMapper
iptables -t nat -A OUTPUT -d $ip -p tcp --dport 135 -m addrtype --dst-type LOCAL -j DNAT --to-destination $ip:13500 -m comment --comment RpcEndPointMapper
iptables-save > /etc/iptables.conf
@roberto-mardeni
roberto-mardeni / gist:61a72b27711465f16e559e756bcabe7d
Created September 19, 2016 15:10
Chef - Delivery Local Unit failure
Robertos-MacBook-Pro:carnival_rhel_base rmardeni$ export RUST_BACKTRACE=1
Robertos-MacBook-Pro:carnival_rhel_base rmardeni$ delivery local unit
Chef Delivery
Running Unit Phase
thread '<main>' panicked at 'Unexpected error: Failed to execute process: No such file or directory (os error 2)', src/delivery/command/local.rs:53
stack backtrace:
1: 0x103110e68 - std::sys::backtrace::tracing::imp::write::h4c73fcd3363076f5
2: 0x103117eb5 - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::h0422dbb3077e6747
3: 0x103117aee - std::panicking::default_hook::haac48fa641db8fa2
4: 0x1030fed56 - std::sys_common::unwind::begin_unwind_inner::h39d40f52add53ef7