Carlos Vargas

Connect to HCP via PowerShell

Blog Post created by Carlos Vargas Employee on Apr 18, 2016

This is a quick blog to help all PowerShell Developers and Administrators to leverage the power of HCP via PowerShell


1. Install the Hitachi Storage Adapter for Microsoft Windows PowerShell



2. Open a Windows PowerShell ISE Window.



3. In order to Add the HDS PowerShell SnapIn to your PowerShell Session follow the following steps.

# Add Hitachi Data System PowerShell SnapIn

Write-Host ""

Write-Host "-------------Importing Hitachi Data System PowerShell Module --------------" -BackgroundColor White -ForegroundColor Black

Add-PSSnapin "Hitachi.Storage.Management.Powershell2.Admin"

Add-PSSnapin "Hitachi.Storage.Management.Powershell.Admin.HCP"





4. Next let us add a function to convert the password into the correct format needed to authenticate against HCP.

# Functions


function ConvertFrom-SecureToPlain {


    param( [Parameter(Mandatory=$true)][System.Security.SecureString] $SecurePassword)


    # Create a "password pointer"

    $PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)


    # Get the plain text version of the password

    $PlainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)


    # Free the pointer



    # Return the plain text password






5. Now let us add a couple of variables for the HCP System name, Username and Password

# Variables

$HCPFQDN = Read-Host "Please Type the FQDN or DNS Name of your HCP System. Ex."

$HCPAdminUser = Read-Host "Please type your administrator acccount username for the HCP System"

# Capture the Password in Encrypted AES form and so it can be secured

$HCPAdminPass = Read-Host "Please type your administrator acccount password for the HCP System" -AsSecureString



6. Let's call the ConvertFrom-SecureToPlain Function and then connect to the HCP

# Convert Password from AES to Appropiate Format

$HCPAdminPassUnEncrypted = ConvertFrom-SecureToPlain($HCPAdminPass)


# Connect to HCP

$ConnectToHCP = Add-HCP -HCPSystem $HCPFQDN -UserID $HCPAdminUser -Password $HCPAdminPassUnEncrypted



7. Now let's connect to the HCP System and store the information in a variable called $HCP

# HCP Details to HCP

$HCP = Get-HCP




8. Now we can execute our script and connect to the HCP System and get some basic information like the current tenants in the HCP.




Hope this has been helpful and that you can use the code to create great scripts.