Thursday 29 January 2015

Powershell Script to Convert xlsx to csv


Use the below code to convert the xlsx file into csv:


$xlsx_file="C:\Users\v-gibag\Desktop\locations.xlsx"
$csv_file="C:\Users\v-gibag\Desktop\user1.csv"
$Excel = new-object -comobject excel.application
$book = $Excel.Workbooks.Open($xlsx_file)
$book.SaveAs($csv_file,6)
$book.Close($false)
$Excel.quit()

Wednesday 28 January 2015

How to submit hive query to HDinsight cluster from Powershell


1. Open azure power shell , please type the following command

    Get-AzurePublishSettingsFile

   It will open Azure login page, enter the credentials
 
       


Once after successful login, the Public settings file will be downloaded automatically.

2. After use the below Import command to import the settings file   
                                     
Import-AzurePublishSettingsFile <path to file>      


3.please use the below script to connect to hive and run hive.


$subscriptionName = "Azure in Open"
PS C:\> $clusterName = "IngramCluster"
PS C:\> Select-AzureSubscription $subscriptionName
PS C:\> Select-AzureSubscription -SubscriptionName $subscriptionName
PS C:\> Use-AzureHDInsightCluster $clusterName
Successfully connected to cluster IngramCluster
PS C:\> Invoke-Hive -Query "select * from hivesampletable limit 5;"

Submitting Hive query..
Started Hive query with jobDetails Id : job_1421995004773_0004
Hive query completed Successfully


8       18:54:20        en-US   Android Samsung SCH-i500        California      United States   13.9204007      0
0
23      19:19:44        en-US   Android HTC     Incredible      Pennsylvania    United States   NULL    0       0
23      19:19:46        en-US   Android HTC     Incredible      Pennsylvania    United States   1.4757422       0
1
23      19:19:47        en-US   Android HTC     Incredible      Pennsylvania    United States   0.245968        0
2
28      01:37:50        en-US   Android Motorola        Droid X Colorado        United States   20.3095339      1