Skip to content

Instantly share code, notes, and snippets.

@vijayjt
vijayjt / kinit_as_hadoop_system_user.sh
Created January 7, 2017 18:00
Easiest way to kinit as hdfs, hive or another Hadoop system user with CDH
export HDPUSER='hive'
export DOMAIN=$(dnsdomainname)
export PKEYTAB=$(ls -Rt /var/run/cloudera-scm-agent/process/*/*keytab | grep $HDPUSER | head -1)
export PRINC=$(klist -kt $PKEYTAB | grep -v FILE | grep $HDPUSER | awk '{print $4}')
kinit -V -kt $PKEYTAB $PRINC
@vijayjt
vijayjt / create-win2k8r2-vm-in-azure-arm.ps1
Last active April 10, 2017 19:30
PowerShell code to create a Windows Server 2008 R2 VM in Azure (for ASE and AD blog post)
# Select a subscritpion
Set-AzureRmContext -SubscriptionName (Get-AzureRmSubscription | Out-GridView -PassThru).SubscriptionName
$Location = 'North Europe'
# Create a resource group for the VM and storage account
$CoreInfraResourceGroupName = 'VM-RG-0001'
New-AzureRmResourceGroup -Name $CoreInfraResourceGroupName -Location $Location
$CoreInfraVMStorageAccount = '0048vhdstorage'
@vijayjt
vijayjt / Windows-Server2008R2-AD-Install.ps1
Created April 10, 2017 19:29
PowerShell code for installing AD and running DC Promo via an Answer file for Win2K8R2 (for ASE and AD blog post)
$AccountName = 'my-admin'
$vmpwd = 'ReplaceWithAStrongPassword'
$SecurePassword = ConvertTo-SecureString $vmpwd -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($AccountName, $SecurePassword);
Import-Module ServerManager
Add-WindowsFeature GPMC, Backup-Features, Backup, Backup-Tools,DNS,WINS-Server -Verbose
Add-WindowsFeature AS-NET-Framework -Verbose
Add-WindowsFeature AD-Domain-Services, ADDS-Domain-Controller -Verbose
@vijayjt
vijayjt / PowerShell-LDAP-Search-Example1.ps1
Created April 10, 2017 19:42
How to search AD using PowerShell
$username = 'aduser'
$password = 'replaceWithPassword'
$DomainControllerIpAddress = '192.168.0.21'
$LdapDn = 'dc=acme,dc=local'
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://$($DomainControllerIpAddress):389/$LdapDn",$username,$password)
# Here look for a user
$ds = new-object System.DirectoryServices.DirectorySearcher($dn)
$ds.filter = "((userPrincipalName=*))"
$ds.SearchScope = "subtree"
@vijayjt
vijayjt / azure-web-app-php-ldap-test.php
Created April 10, 2017 19:47
Code for testing LDAP connection from an Azure Web App in an ASE to a AD DC in a VNet
<?php
$domain = 'acme.local';
$username = 'aduser';
$password = 'replaceWithPassword';
$ldapconfig['host'] = '192.168.21';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=acme,dc=local';
$ldap_dn = "DC=acme,DC=local";
@vijayjt
vijayjt / Get-AzureIPRangesXMLFile.ps1
Last active July 31, 2017 12:25
PowerShell function to download the Azure Public IP Ranges file and save it locally
Function Get-AzurePublicIPRangesXMLFile
{
<#
.SYNOPSIS
This function downloads the Azure IP ranges XML file to the current directory or a specified path.
.DESCRIPTION
This function downloads the Azure IP ranges XML file to the current directory or a specified path.
.PARAMETER AzureIPRangeURL
An optional parameter that is the URL to the Azure IP range XML file download page.
.PARAMETER DestinationPath
@vijayjt
vijayjt / Get-AzurePubicIpXMLRegionList.ps1
Last active May 21, 2017 10:02
Return the regions in the Azure Public IP XML file
Function Get-AzurePubicIpXMLRegionList
{
<#
.SYNOPSIS
The function takes the Azure Public IP address XML file and returns an array of region names
.DESCRIPTION
The function takes the Azure Public IP address XML file and returns an array of region names
.PARAMETER AzureIPRangeXMLFile
The XML file containing the Azure IP ranges.
.EXAMPLE
@vijayjt
vijayjt / Get-AzureRegionPublicIPAddressList.ps1
Created May 21, 2017 09:47
The function lists the public IP addresses in a particular Azure region
Function Get-AzureRegionPublicIPAddressList
{
<#
.SYNOPSIS
The function lists the public IP addresses in a particular Azure region
.DESCRIPTION
The function lists the public IP addresses in a particular Azure region.
.PARAMETER Region
The Azure region for which you want to retrieve public IP addresses.
.PARAMETER AzureIPRangeXMLFile
@vijayjt
vijayjt / create-azure-ad-app-and-spn-multiple-certs.ps1
Last active October 2, 2017 17:18
Create an Azure AD App with Multiple Certs for Authentication
Login-AzureRmAccount
# Create the self signed cert
mkdir c:\certificates
$currentDate = Get-Date
$endDate = $currentDate.AddYears(1)
$notAfter = $endDate.AddYears(1)
$pwdplaintext = "P@ssW0rd1"
@vijayjt
vijayjt / hdinsight-ambari-examples.sh
Last active October 3, 2017 15:19
HDInsight Ambari REST API examples - check out my repo AzureHDInsight for the full code
function check_ambari_user_exists()
{
USER_TO_CHECK=$1
# Get list of users in Ambari
USER_LIST=$(curl -u "$USERID:$PASSWD" -sS -G "http://${ACTIVEAMBARIHOST}:8080/api/v1/users" | grep 'user_name' | cut -d":" -f2 | tr -d '"','',' ' )
for User in $( echo "$USER_LIST" | tr '\r' ' '); do
echo "-${User}-"
if [ "$User" == "$USER_TO_CHECK" ];then
echo 0