VMware Solutions Discussions

NetApp VSC Powershell Toolkit

datacenterdude
28,028 Views

All,

Some of you are familiar with our previous "kamino" powershell cmdlets/module.  The problem with that is that is was focused on one particular functional area of VSC:   Provisioning & Cloning.

That simply does not scale well.

So we went back to the drawing board, and did some renaming of the code.

Caveats:

  • Functionally, these are identical actions to the previous kamino cmdlets.
  • We have renamed things to be more generic, or all-encompassing, as we begin down the path of adding APIs for many tasks in the VSC.
  • We understand that many of you already have scripts in place using the older stuff, but please understand, all you need to change is the module that gets loaded, and the cmdlet names used.

Going forward:

  • As we add new APIs to VSC, we will also be adding equivalent cmdlets for that functionality.

If you have any questions, or run into any issues with the toolkit/module, please post them here!

Usage:

PS> Import-Module C:\Path-to-DLL\NetAppVSC.dll

PS> Get-Command -Module NetAppVSC

CommandType     Name

-----------     ----

Cmdlet          Connect-vsc

Cmdlet          Get-vscManagedObjectRef

Cmdlet          Get-vscVirtualMachine

Cmdlet          Get-vscVmFileSpec

Cmdlet          New-vscControllerSpec

Cmdlet          New-vscDatastore

Cmdlet          Remove-vscDatastore

Cmdlet          Set-vscDatastoreSize

Cmdlet          Start-vscClone

Cmdlet          Start-vscRedeploy

Thanks!

UPDATE:  Due to some inconsistencies we have found with the .dll (we think compiling corruption on the final build) we've pulled this down temporarily so that it doesn't proliferate further, and will get a new version up ASAP.  Please remember that this isn't something officially sanctioned by NetApp, but something that 1 or 2 of us are doing in our spare time.  Thank you for your patience, and we'll get it back very soon, I promise!

UPDATE: I am posting the original rebranded toolkit!  Please let know how this works!


-Nick

35 REPLIES 35

thomi11__
10,471 Views

I'm not sure if this is the right place to ask, but I'm unable to get Start-vscClone to work I get the following error when I try to use it, I really hope someone here can help me out!

Start-vscClone : The request failed with HTTP status 404: Not Found.

At C:\win32app\PowerCLI\testclone.ps1:31 char:26

+ $taskRef = Start-vscClone <<<<  -clonespec $cloneSpec

    + CategoryInfo          : InvalidOperation: (com.netapp.vsc.vscServer:vscServer) [Start-vscClone], WebException

    + FullyQualifiedErrorId : ApiError,com.netapp.vsc.cmdlets.StartvscClone

mbeattie
10,471 Views

Hi Mike,

Sure, you've arrived at the right place and I hope i can help....

I'm assuming you trying to use the vsc.dll Nick uploaded? I wasn't able to get that working either and as far as i'm aware there has been no development on powershell toolkit since VSC2.X. I believe the future method of VSC automation is to enable customers to invoke VSC API's directly as opposed to relying on compiled C# cmdlets which require updating as API's as added or depreciated in future VSC versions. The API documentation is availabe in the VSC installation and administration guide available here:

https://library.netapp.com/ecm/ecm_get_file/ECMP1149724

As the documentation does not provide examples, I developed code to invoke the VSC API's via web services (SOAP) and posted them. Here are some examples: 

https://communities.netapp.com/thread/30999 (VSC Rapid Clone and Resize DataStore API examples in PowerShell)
https://communities.netapp.com/message/121856 (VSC Redeploy API example in PowerShell)
https://communities.netapp.com/docs/DOC-30692 (WFA workflow to Create Rapid Clones)

As for the error you recieved a useful troubleshooting tool is the VMware MOB (Managed Object Browser). This is really useful to determine if the vSphere object you attempting to reference exists.

http://pubs.vmware.com/vsphere-55/topic/com.vmware.wssdk.pg.doc/PG_Appx_Using_MOB.20.2.html#994699

Hope that helps?

Cheers Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

thomi11__
9,198 Views

Hey Matt, I have just continued to manually invoke the netapp rapid clone applet within vSphere, but still really need to get this automated, so I've set aside some time to get this going.  I'm not sure your example for rapid-clones is how I used the rapid-clone applet in vSphere.  I invoke it on a existing VM (template) and then select where the clones will be placed within the vCenter heirarchy then the netapp to use and the NFS storage on that netapp.  I then say I want 1000 clones, named prefix- starting with 10000 and incremented by 1.  How does this map to your example?

 

Thanks for your help!

 

Mike

mbeattie
9,191 Views

Hi Mike,

 

What mode of Data ONTAP are you using? 7-Mode or clustered Data ONTAP? What version of vSphere are you using? If you are using vSphere 6.X then there is a powershell module for VSC6 available here:

 

VSC6.1 http://mysupport.netapp.com/NOW/download/software/vsc_win/6.1/VSC-6.1.zip

Virtual Storage Console 6.1 for VMware vSphere Reference Guide for APIs and PowerShell Cmdlets https://library.netapp.com/ecm/ecm_get_file/ECMP12484464

 

Your options are use the powershell cmdlet's if you are running vSphere 6.X or invoke the VSC API's using web services\SOAP (this is available in any version of VSC). Based on which version of ontap you are using i can share an example of how to invoke the VSC API's using SOAP.

 

As for an example of how to create a number of clones using naming standard...the following code provides an example (but for creating the Active Directory computer account objects for your clones) which you will need to do before you create the VSC rapid clones (I'm assuming this is how you are using VSC when creating clones...IE create X number of clones matching the computer naming standard ABC)

 

 

<#'-----------------------------------------------------------------------------
'Command Name : create_computer_accounts
'Author       : Matthew Beattie
'Email        : mbeattie@netapp.com
'Created      : 2015-11-28
'Description  : This WFA command creates a specified number of Active Directory
'             : Computer Account Objects in an Organizational Unit matching a
'             : specified naming standard.
'-----------------------------------------------------------------------------#> 
param(
   [Parameter(Mandatory=$True, HelpMessage="The hostname of the Active Directory Computer Account to create")]
   [String]$HostName,
   [Parameter(Mandatory=$True, HelpMessage="The hostname naming prefix of the Active Directory Computer Account to create")]
   [String]$HostNamePrefix,
   [Parameter(Mandatory=$True, HelpMessage="The hostname naming prefix of the Active Directory Computer Account to create")]
   [Int]$HostNameCount,
   [Parameter(Mandatory=$True, HelpMessage="The Distinguished Name of the Organizational Unit to create the Computer Account in")]
   [String]$OrganizationalUnit,
   [Parameter(Mandatory=$True, HelpMessage="A comma delimited list of hostnames or IP Addresses of Domain Controllers")]
   [String]$DomainControllers
)
#'------------------------------------------------------------------------------
#'Ensure the NetBIOS hostname is valid as per: https://support.microsoft.com/en-us/kb/909264
#'------------------------------------------------------------------------------
Function Check-HostName{
   Param(
      [Parameter(Mandatory=$True, HelpMessage="The hostname of the Active Directory Computer Account to validate")]
      [String]$HostName
   )
   #'---------------------------------------------------------------------------
   #'Create a hashtable of disallowed characters in NetBIOS hostnames and DNS records.
   #'---------------------------------------------------------------------------
   [HashTable]$disAllowed = @{"`\" = "`\"; "`/" = "`/"; "`:" = "`:"; "`*" = "`*"; "`?" = "`?";
                              """" = """"; "`<" = "`<"; "`>" = "`>"; "`|" = "`|"; "`," = "`,";
                              "`!" = "`!"; "`@" = "`@"; "`#" = "`#"; "`$" = "`$"; "`%" = "`%";
                              "`^" = "`^"; "`&" = "`&"; "`'" = "`'"; "`." = "`."; "`(" = "`(";
                              "`)" = "`)"; "`{" = "`{"; "`}" = "`}"; "`_" = "`_"; "` " = "` ";}
   #'---------------------------------------------------------------------------
   #'Ensure none of the invalid characters are contained in the NetBIOS hostname.
   #'---------------------------------------------------------------------------
   ForEach($key In $disAllowed.Keys){
      If($HostName.Contains($key)){
         Get-WFALogger -Error -Message "The character ""$key"" is invalid in NetBIOS hostname ""$HostName"""
         Return $False;
      }
   }
   If(($HostName.Length -gt 0) -And ($HostName.Length -ge 16)){
      Get-WFALogger -Error -Message "The hostname ""$HostName"" is greater than 15 characters"
      Return $False;
   }Else{
      If($HostName -eq $Null -Or $HostName -eq ""){
         Get-WFALogger -Error -Message "The hostname is null or empty"
         Return $False;
      }
   }
   Return $True;
}#End Function
#'------------------------------------------------------------------------------
#'Validate the NetBIOS hostname.
#'------------------------------------------------------------------------------
[String]$HostName       = $HostName.ToUpper();
[String]$hostNameNumber = $HostName.Replace($HostNamePrefix, "")
[String]$url            = "https://support.microsoft.com/en-us/kb/909264"
If(-Not(Check-HostName -HostName $HostName)){
   Throw "The NetBIOS hostname ""$HostName"" is invalid. Please refer to Microsoft KB article ""$url"" for NetBIOS hostname naming standards"
}Else{
   #Get-WFALogger -Info -Message "The hostname ""$HostName"" is valid as per Microsoft KB Article ""$url"" for NetBIOS hostname naming standards"
   Write-Host "The hostname ""$HostName"" is valid as per Microsoft KB Article ""$url"" for NetBIOS hostname naming standards"
}
#'------------------------------------------------------------------------------
#'Ensure the comma delimited list of Domain Controllers is converted to an array.
#'------------------------------------------------------------------------------
If($domainControllers.Contains(",")){
   [Array]$ipAddresses = $DomainController.Split(",")
}Else{
   [Array]$ipAddresses = $DomainControllers
}
[Bool]$continue = $False
ForEach($ipAddress In $ipAddresses){
   #'---------------------------------------------------------------------------
   #'Resolve the IP Address to the Domain Controllers hostname.
   #'---------------------------------------------------------------------------
   If($ipAddress -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"){
      [String]$dc = [System.Net.Dns]::GetHostEntry($ipAddress).HostName
      #Get-WFALogger -Info -Message "Resolved IP Address ""$ipAddress"" to hostname ""$dc"""
      Write-Host "Resolved IP Address ""$ipAddress"" to hostname ""$dc"""
   }Else{
      [String]$dc = $ipAddress
   }
   #'---------------------------------------------------------------------------
   #'Ensure the Domain Controller name is set to it's NetBIOS hostname. 
   #'---------------------------------------------------------------------------
   If($dc.Contains(".")){
      [String]$DomainController = $dc.Split(".")[0]
   }Else{
      [String]$DomainController = $dc
   }
   #'---------------------------------------------------------------------------
   #'Check if the domain controller replies to an ICMP Request. 
   #'---------------------------------------------------------------------------      
   Try{
      $reply = Test-Connection -ComputerName $DomainController -Count 1 -ErrorAction Stop
      #Get-WFALogger -Info -Message "The Domain Controller ""$DomainController"" responded to an ICMP Request"
      Write-Host "The Domain Controller ""$DomainController"" responded to an ICMP Request"
      [Bool]$continue = $True
      Break;
   }Catch{
      #Get-WFALogger -Error -Message "The Domain Controller ""$DomainController"" did not respond to an ICMP Request"
      Write-Warning -Message "The Domain Controller ""$DomainController"" did not respond to an ICMP Request"
   }
}
#'------------------------------------------------------------------------------
#'Set the Domain Controller to the WFA servers logon server if not provided.
#'------------------------------------------------------------------------------
If($DomainController -eq $Null -Or $DomainController -eq ""){
   [String]$DomainController = ($env:logonserver -Replace("\\", "")).ToLower();
   Try{
      $reply = Test-Connection -ComputerName $DomainController -Count 1 -ErrorAction Stop
      #Get-WFALogger -Info -Message "The Domain Controller ""$DomainController"" responded to an ICMP Request"
      Write-Host "The Domain Controller ""$DomainController"" responded to an ICMP Request"
      [Bool]$continue = $True
   }Catch{
      #Get-WFALogger -Error -Message "The Domain Controller ""$DomainController"" did not respond to an ICMP Request"
      Write-Warning -Message "The Domain Controller ""$DomainController"" did not respond to an ICMP Request"
   }
}
#'------------------------------------------------------------------------------
#'Exit if there were no domain controllers available.
#'------------------------------------------------------------------------------
If(-Not($continue)){
   Throw "Failed to contact a domain controller"
}
#'------------------------------------------------------------------------------
#'Bind to the Organizational Unit to create the computer accounts in.
#'------------------------------------------------------------------------------
Try{
   $ou = [ADSI]"LDAP://$DomainController/$OrganizationalUnit"
   #Get-WFALogger -Info -Message "Performed LDAP Bind to Organizational Unit ""LDAP://$DomainController/$OrganizationalUnit"""
   Write-Host "Performed LDAP Bind to Organizational Unit ""LDAP://$DomainController/$OrganizationalUnit"""
}Catch{
   #Get-WFALogger -Error -Message $("Failed binding to organizational unit ""LDAP://$DomainController/$OrganizationalUnit"" on Domain Controller ""$DomainController"". Error " + $_.Exception.Message)
   Write-Host -Message $("Failed binding to organizational unit ""LDAP://$DomainController/$OrganizationalUnit"" on Domain Controller ""$DomainController"". Error " + $_.Exception.Message)
   Throw "Failed binding to organizational unit ""LDAP://$DomainController/$OrganizationalUnit"" on Domain Controller ""$DomainController"""
}
#'------------------------------------------------------------------------------
#'Process the number of clones
#'------------------------------------------------------------------------------
[Int]$errorCount = 0
For($i = ([Int]$hostNameNumber); $i -le ([Int]$hostNameNumber + $HostNameCount); $i++){
   Do{
      #'------------------------------------------------------------------------
      #'Set the hostname name
      #'------------------------------------------------------------------------
      [String]$hostNumber   = $i.ToString().PadLeft($hostNameNumber.Length, "0")
      [String]$computerName = "$HostNamePrefix$hostNumber"
      #'------------------------------------------------------------------------
      #'Create the computer account in the Organizational Unit.
      #'------------------------------------------------------------------------
      Try{
         $computer = $ou.Create("Computer", "CN=$computerName")
         $computer.Put("sAMAccountName", "$computerName`$")
         $computer.Put("userAccountControl", 4128)
         $computer.SetInfo();
         #Get-WFALogger -Info -Message "Created Computer Account ""$computerName"" in Organizational Unit ""$OrganizationalUnit"" on Domain Controller ""$DomainController"""
         Write-Host "Created Computer Account ""$computerName"" in Organizational Unit ""$OrganizationalUnit"" on Domain Controller ""$DomainController"""
      }Catch{
         #Get-WFALogger -Error -Message $("Failed creating computer account ""$computerName"" in Organizational Unit ""$OrganizationalUnit"". Error " + $_.Exception.Message)
         Write-Host -Message $("Failed creating computer account ""$computerName"" in Organizational Unit ""$OrganizationalUnit"". Error " + $_.Exception.Message)
         [Int]$errorCount = $errorCount + 1
      }
   }Until($True)
}
#'------------------------------------------------------------------------------
#'Ensure an error is raised if there were any failures.
#'------------------------------------------------------------------------------
If($errorCount -ne 0){
   Throw "Failed creating computer accounts in Organizational Unit ""$OrganizationalUnit"""
}
#'------------------------------------------------------------------------------

Note that i've commented out some lines for the "Get-WFALogger" statement and replaced them with Write-Host or Write-Warning (so it will work if you run it from a powershell prompt)...This is because i've cut\pasted my code from OnCommand Workflow Automation (WFA). The same code will work in WFA or in Powershell. EG:

 

 

 

PS C:\Scripts\PowerShell\Projects\CreateComputerAccounts> .\CreateComputerAccounts.ps1 -HostName TESTWS111 -HostNamePrefix TESTWS -HostNameCount 10 -OrganizationalUnit "OU=Desktops,DC=testlab,DC=local" -DomainControllers testdc01
The hostname "TESTWS111" is valid as per Microsoft KB Article "https://support.microsoft.com/en-us/kb/909264" for NetBIOS hostname naming standards
The Domain Controller "testdc01" responded to an ICMP Request
Performed LDAP Bind to Organizational Unit "LDAP://testdc01/OU=Desktops,DC=testlab,DC=local"
Created Computer Account "TESTWS111" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS112" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS113" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS114" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS115" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS116" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS117" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS118" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS119" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS120" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"
Created Computer Account "TESTWS121" in Organizational Unit "OU=Desktops,DC=testlab,DC=local" on Domain Controller "testdc01"

however i would recommend that if you are going to invest your time in automating this in your environment then you write workflows instead of scripts.

 

You can download WFA for FREE here:

 

http://mysupport.netapp.com/download/software/ocwfa/3.1P1

 

Let me know what versions you are running and i can provide some examples to integrate that with VSC rapid clones.

 

/matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

thomi11__
9,102 Views

The clones are all RedHat linux systems, no active directory etc will be involved and the names I'm referring to are just the VM names in vCenter/vSphere.  I have designed a full system that manages deploying systems and automatically installing the product we develop for automated testing etc.  The clones are really just pre-cloned VMs sitting in wait in a pool and when they are needed they are configured and renamed to the hostname they will become as they turn on.  So the only part I'm missing that isn't automated is the cloning process to fill the pool of VMs waiting to be deployed.  Up til now I've just used vSphere Client and the netapp add-on for vCenter that allows to manually clone a bunch of VMs.

 

My NetApp is running 8.1.4P1 and is only 7-mode.  My vCenter is 5.0.0U3.

 

Thanks, Mike

mbeattie
9,097 Views

Hi Mike,

 

Here is an example for you from a WFA command to create rapid clones using Powershell and SOAP. You'd need to combine to the logic from the code to create the computer accounts as this just accepts a comma delimited list of hostnames.

 

Param(
  [Parameter(Mandatory = $True,  HelpMessage = "The Controller Name")] 
  [String]$ControllerHostName, 
  [Parameter(Mandatory = $False, HelpMessage = "The Controller IP Address")] 
  [String]$ControllerIPAddress, 
  [Parameter(Mandatory = $True,  HelpMessage = "The vFiler HostName")] 
  [String]$VFilerHostName, 
  [Parameter(Mandatory = $True,  HelpMessage = "The VSC HostName")] 
  [String]$VscHostName, 
  [Parameter(Mandatory = $True,  HelpMessage = "The VSC Port Number")]
  [Int]$PortNumber, 
  [Parameter(Mandatory = $True,  HelpMessage = "The vCenter DataCenter Name")]
  [String]$DataCenterName,
  [Parameter(Mandatory = $True,  HelpMessage = "The vCenter DataStore Name")]
  [String]$DataStoreName,
  [Parameter(Mandatory = $True,  HelpMessage = "The vCenter Virtual Machine Template Name")]
  [String]$TemplateName,
  [Parameter(Mandatory = $True,  HelpMessage = "The vCenter Customization Name")]
  [String]$CustomizationName,
  [parameter(Mandatory = $True,  HelpMessage = "Comma delimited List of Virtual Machine Names to create")]
  [String]$HostNames,
  [parameter(Mandatory = $True,  HelpMessage = "Specified if the Virtual Machine Clones should be powered on")]
  [Bool]$PowerOn  
) 
#'------------------------------------------------------------------------------ 
#'Convert the Hostnames parameter from a comma delimited string to an array.
#'------------------------------------------------------------------------------
If($HostNames -Match ","){
   [Array]$cloneNames = $HostNames -Split(",")
}Else{
   [Array]$cloneNames = @($HostNames)
}
#'------------------------------------------------------------------------------
#'Enumerate the VSC Credentials from WFA.
#'------------------------------------------------------------------------------
Try{
   [System.Management.Automation.PSCredential]$vscCredentials = Get-WfaCredentials -Host $VscHostName -ErrorAction Stop
}Catch{
   Get-WFALogger -Error -Message $("Failing enumerating Credentials for ""$VscHostName"". Error " + $_.Exception.Message)
   Throw "Failing enumerating Credentials for ""$VscHostName"""
}
#'------------------------------------------------------------------------------
#'Enumerate the Controller Credentials from WFA.
#'------------------------------------------------------------------------------
Try{
   [System.Management.Automation.PSCredential]$controllerCredentials = Get-WfaCredentials -Host $ControllerHostName -ErrorAction Stop
}Catch{
   Get-WFALogger -Error -Message $("Failing enumerating Credentials for ""$ControllerHostName"". Error " + $_.Exception.Message)
   Throw "Failing enumerating Credentials for ""$ControllerHostName"""
}
#'------------------------------------------------------------------------------
#'Connect to the VSC via web services.
#'------------------------------------------------------------------------------
[String]$vscUri = "https://$VscHostName`:$PortNumber/kamino/public/api?wsdl"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}
Try{
   [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `
   New-WebServiceProxy -uri $vscUri -Credential $vscCredentials -ErrorAction Stop
   Get-WFALogger -Info -Message "Connected to VSC ""$vscUri"""
}Catch{
   Get-WFALogger -Error -Message $("Failed connecting to ""$vscUri"". Error " + $_.Exception.Message)
   Throw "Failed connecting to ""$vscUri"""
}
#'------------------------------------------------------------------------------
#'Enumerate the VSC namespace
#'------------------------------------------------------------------------------
[System.Object]$namespace = $connection.GetType().Namespace
#'------------------------------------------------------------------------------
#'Enumerate the VSC username and password from the Credential object
#'------------------------------------------------------------------------------
[String]$vscDomain   = $vscCredentials.GetNetworkCredential().domain
[String]$vscUser     = $vscCredentials.GetNetworkCredential().username
[String]$vscPassword = $vscCredentials.GetNetworkCredential().password
#'------------------------------------------------------------------------------
#'Set the VSC username to a local or domain user.
#'------------------------------------------------------------------------------
If(($vscDomain -ne $Null) -Or ($vscDomain -ne "")){
   [String]$vscUsername = "$vscDomain\$vscUser"
}Else{
   [String]$vscUserName = $vscUser
}
#'------------------------------------------------------------------------------
#'Enumerate the Controller username and password from the Credential object
#'------------------------------------------------------------------------------
[String]$controllerDomain   = $ControllerCredentials.GetNetworkCredential().domain
[String]$controllerUser     = $ControllerCredentials.GetNetworkCredential().username
[String]$controllerPassword = $ControllerCredentials.GetNetworkCredential().password
#'------------------------------------------------------------------------------
#'Create a requestSpec object and set it's credentials.
#'------------------------------------------------------------------------------
[System.Object]$requestSpecType        = ($namespace + '.requestSpec')
[System.Object]$requestSpec            = New-Object ($requestSpecType)
[System.Object]$requestSpec.serviceUrl = "https://" + $vscHostName + "/sdk"
[System.Object]$requestSpec.vcUser     = $vscUsername
[System.Object]$requestSpec.vcPassword = $vscPassword
#'------------------------------------------------------------------------------
#'Enumerate the managed object reference for the datacenter.
#'------------------------------------------------------------------------------
Try{
   [String]$dataCenterMoref = $connection.getMoref($DataCenterName, "Datacenter", $requestSpec)
   Get-WFALogger -Info -Message "Enumerated Managed Object Reference for ""$DataCenterName"" as ""$DataCenterMoref"""
}Catch{
   Get-WFALogger -Error -Message $("Enumerated Managed Object Reference for ""$DataCenterName"" as ""$DataCenterMoref"". Error " + $_.Exception.Message)
   Throw "Enumerated Managed Object Reference for ""$DataCenterName"" as ""$DataCenterMoref"""
}
#'------------------------------------------------------------------------------
#'Enumerate the managed object reference for the datastore.
#'------------------------------------------------------------------------------
Try{
   [String]$dataStoreMoref = $connection.getMoref($DataStoreName, "Datastore", $requestSpec)
   Get-WFALogger -Info -Message "Enumerated Managed Object Reference for ""$DataStoreName"" as ""$dataStoreMoref"""
}Catch{
   Get-WFALogger -Error -Message $("Failed Enumerating Managed Object Reference for ""$DataStoreName"". Error " + $_.Exception.Message)
   Throw "Failed Enumerating Managed Object Reference for ""$DataStoreName"""
}
#'------------------------------------------------------------------------------
#'Enumerate the managed object reference for the Virtual Machine.
#'------------------------------------------------------------------------------
Try{
   [String]$templateMoref = $connection.getMoref($TemplateName, "VirtualMachine", $requestSpec)
   Get-WFALogger -Info -Message "Enumerated Managed Object Reference for ""$TemplateName"" as ""$templateMoref"""
}Catch{
   Get-WFALogger -Error -Message $("Failed Enumerating Managed Object Reference for ""$TemplateName"". Error " + $_.Exception.Message)
   Throw "Failed Enumerating Managed Object Reference for ""$TemplateName"""
}
#'------------------------------------------------------------------------------
#'Enumerate the template virtual machine files.
#'------------------------------------------------------------------------------
$files = $connection.getVMFiles($templateMoref, $requestSpec)
#'------------------------------------------------------------------------------
#'Create a controllerSpec Object from the NameSpace object and set properties.
#'------------------------------------------------------------------------------
[System.Object]$controllerType                    = ($namespace + '.controllerspec')
[System.Object]$controllerSpec                    = New-Object ($controllerType)
[System.Object]$controllerSpec.username           = $controllerUser
[System.Object]$controllerSpec.password           = $controllerPassword
[System.Object]$controllerSpec.ipAddress          = $ControllerIPAddress
[System.Object]$controllerSpec.passthroughContext = $VFilerHostName
[System.Object]$controllerSpec.ssl                = $True
#'------------------------------------------------------------------------------
#'Set the destination controller and datastore for the files.
#'------------------------------------------------------------------------------
ForEach($file In $files){
   $file.destDatastoreSpec.controller = $controllerSpec;
}
#'------------------------------------------------------------------------------
#'Create a cloneSpec Object from the NameSpace object and set properties.
#'------------------------------------------------------------------------------
[System.Object]$cloneSpecType            = ($namespace + '.cloneSpec')
[System.Object]$cloneSpec                = New-Object ($cloneSpecType)
[System.Object]$cloneSpec.templateMoref  = $templateMoref;
[System.Object]$cloneSpec.containerMoref = $dataCenterMoref;
#'------------------------------------------------------------------------------
#'Create objects for each clone and set their properties.
#'------------------------------------------------------------------------------
[Array]$clones = @()
For($i = 0; $i -le ($cloneNames.Count -1); $i++){
   #'---------------------------------------------------------------------------
   #'Create a vmSpec Object from the NameSpace object and set properties.
   #'---------------------------------------------------------------------------
   [System.Object]$vmSpecType = ($namespace + '.vmSpec')
   [System.Object]$vmSpec     = New-Object ($vmSpecType)
   #'---------------------------------------------------------------------------
   #'Create a cloneSpecEntry Object from the NameSpace object and set properties.
   #'---------------------------------------------------------------------------
   [System.Object]$cloneSpecEntryType = ($namespace + '.cloneSpecEntry')
   [System.Object]$cloneSpecEntry     = New-Object ($cloneSpecEntryType)
   #'---------------------------------------------------------------------------
   #'Create a guestCustomizationSpecType Object from the NameSpace object and set properties.
   #'---------------------------------------------------------------------------
   [System.Object]$guestCustomizationSpecType  = ($namespace + '.guestCustomizationSpec')
   [System.Object]$guestCustomizationSpec      = New-Object ($guestCustomizationSpecType)
   [System.Object]$guestCustomizationSpec.Name = $CustomizationName
   [System.Object]$vmSpec.powerOn              = $PowerOn
   [System.Object]$vmSpec.custSpec             = $guestCustomizationSpec
   [System.Object]$cloneSpecEntry.key          = $cloneNames[$i]
   [System.Object]$cloneSpecEntry.Value        = $vmSpec
   [Array]$clones                             += $cloneSpecEntry
   #'---------------------------------------------------------------------------
   #'Set the destination controller and datastore for the files.
   #'---------------------------------------------------------------------------
   ForEach($file In $files){
      $file.destDatastoreSpec.controller = $controllerSpec;
      $file.destDatastoreSpec.mor        = $dataStoreMoref;
   }
}
#'------------------------------------------------------------------------------
#'Set the properties of the cloneSpec Object.
#'------------------------------------------------------------------------------
[System.Object]$cloneSpec.files  = $files
[System.Object]$cloneSpec.clones = $clones
#'------------------------------------------------------------------------------
#'Set the CloneSpec property of the requestspec Object.
#'------------------------------------------------------------------------------
[System.Object]$requestSpec.CloneSpec = $cloneSpec
#'------------------------------------------------------------------------------
#'Invoke the VSC CreateClones Method.
#'------------------------------------------------------------------------------
Try{
   [String]$vCenterTask = $connection.CreateClones($requestSpec)
   Get-WFALogger -Info -Message "Initiated VSC Rapid Clones vCenter $vCenterTask"
}Catch{
   Get-WFALogger -Error -Message $("Failed Initiating VSC Rapid Clones. Error " + $_.Exception.Message)
   Throw "Failed Initiating VSC Rapid Clones"
}
#'------------------------------------------------------------------------------ 

It would be possilbe to achieve the same result using PERL and SOAP. There is a version of WFA available for Linux if you want to create a workflow instead of script.

 

http://mysupport.netapp.com/download/software/ocwfa_linux/3.1P1

 

/matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

NICKBARTON
10,471 Views

I am unable to get the module loaded. I get the following error:

Import-Module : Could not load file or assembly 'file:///C:\Windows\System32\WindowsPowerShell\v1.0\Modules\VSC\NetAppV

SC.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

At line:1 char:14

+ Import-Module <<<<  C:\Windows\System32\WindowsPowerShell\v1.0\Modules\VSC\NetAppVSC.dll

    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileLoadException

    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

I've tried it from diffrerent folders so it doesn't appear to be an access issue. Is there a dependency I am missing? .NET v?

ndajon
10,378 Views

Hi,

is this NetApp VSC Powershell Toolkit 1.2 supported with VSC 4.x ou 5.0 ?

Thanks in advance,

 

Nicolas

chao
9,817 Views

same question!  Is there new version or if the current version 1.2 support VSC 4.x and 5.0?

MTLombardi
9,655 Views

Is there a later version of this module? The later releases of VSC itself seem to sound as though they include powershell cmdlets, but I'm trying to confirm.

 

Thank you!

railroadmanuk
9,524 Views

The VSC 6.0 download does include the PowerShell module with it, this is in the 'vsc-cmdlets.zip' file. If you extract this, and then run 'Import-Module "<path_to_extracted_files>\VSC.dll"', then this will import the module, and then you can see the commands available by running 'Get-Command -module VSC' (as Nick said). This still shows as v1.0 when I run 'Get-Module -Name VSC | fl' though so assuming that NetApp have not updated this for a while.

CASTLE_ROCK_IT
7,689 Views

Hello!

 

I'm currently using VSC 6.2P1 and downloaded the cmdlet .zip from the site. I've gone and extracted files and tried running import-module c:\temp\vsc.dll but yet get the following errors:

 

PS C:\temp\VSC_Powershell> Import-Module C:\temp\VSC_Powershell\VSC.dll
Import-Module : Could not load file or assembly 'file:///C:\temp\VSC_Powershell\VSC.dll' or one of its dependencies.
Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Import-Module C:\temp\VSC_Powershell\VSC.dll
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

 

 

Not sure the issue, wasn't sure if anyone else experienced this.

mbeattie
7,640 Views

Hi,

 

I've found several issues with the VSC PowerShell module. In the interest of sharing, here are the issues and their solutions:

 

Issue 1:

 

The Module fails to import with error 0x80131515 EG:

 

PS C:\> Import-Module VSC

Import-Module : Could not load file or assembly

'file:///C:\Windows\system32\WindowsPowerShell\v1.0\Modules\VSC\VSC.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

At line:1 char:1
+ Import-Module VSC
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

 

Solution:

 

Extract the “vsc-cmdlets.zip” file to a temporary location. For each file in the extracted VSC folder and subfolers, right click on the file and select properties. Click “Unblock”, “Apply” and “OK” for each file.

 

vsc.jpg

 

Copy the extracted “VSC” folder to the Windows PowerShell module directory (See https://technet.microsoft.com/en-us/library/dd878350%28v=vs.85%29.aspx to determine the appropriate Windows PowerShell Module directory location for your environment)

 

Issue 2:

 

The “VSC.dll.config” file may contain the developers IP Address (10.60.170.210)

 

Solution:

 

Logon to the VSC server, open a command prompt and run an “ipconfig”.

Open the “VSC.dll.config” file and replace “10.60.170.210” with your VSC servers IP Address. EG

 

C:\>ipconfig | find /i "ipv4"

   IPv4 Address. . . . . . . . . . . : 192.168.100.12

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="VscWsApiImplPortBinding"/>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://192.168.100.12:9060/wsapi/v1/vscWSApi"
                binding="basicHttpBinding" bindingConfiguration="VscWsApiImplPortBinding"
                contract="VscAPIs.VscWsApi" name="VscWsApiImplPort" />
        </client>
    </system.serviceModel>
</configuration>

Note: I would recommend creating a DNS Cname alias called “vsc” and update the “VSC.dll.config” file to use the CName alias FQDN rather than hard coding an IP Address. EG

 

C:\>nslookup vsc

Server:  testdc01.testlab.local
Address:  192.168.100.10

Name:    testvc01.testlab.local
Address:  192.168.100.12
Aliases:  vsc.testlab.local

 

Issue 3:

 

The VSC PowerShell modules has system requirement that may not work on older windows operating systems and PowerShell Versions.

 

Solution:

 

Check the PowerShell Manifest file included with the VSC module note that the minimum PowerShell version is 3.0 and the .NET framework 4.5 must be installed.

 

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\VSC\VSC>type VSC.psd1

@@{
  ModuleToProcess        = ''
  ModuleVersion          = '1.0'
  GUID                   = '7784ba43-c2d6-44df-a071-5ac409a2cbb7'
  Author                 = 'NetApp'
  CompanyName            = 'NetApp'
  Copyright              = 'Copyright (c) 2015 NetApp, Inc. All rights reserved.'
  Description            = 'Virtual Storage Console PowerShell Toolkit'
  PowerShellVersion      = '3.0'
  DotNetFrameworkVersion = '4.5'
  RequiredAssemblies     = ''
  NestedModules          = 'VSC.dll'
  FunctionsToExport      = '*'
  CmdletsToExport        = '*'
  VariablesToExport      = '*'
  AliasesToExport        = '*'}

Verify that the .NET framework 4.5 is installed before attempting to import the VSC PowerShell module.

Open a PowerShell prompt and type the following command:

 

PS C:\> Get-WindowsFeature | Where-Object {$_.Name -Match "NET-Framework" -And $_.InstallState -eq "installed"}

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] .NET Framework 3.5 Features                         NET-Framework-Features         Installed
[X] .NET Framework 3.5 (includes .NET 2.0 and 3.0)      NET-Framework-Core             Installed
[X] .NET Framework 4.5 Features                         NET-Framework-45-Fea...        Installed
[X] .NET Framework 4.5                                  NET-Framework-45-Core          Installed

Note: The .NET 4.5 framework is installed by default on Windows Server 2012 R2

 

Once you've ensured a compatible version of the .NET framework is installed before attempting to import the VSC PowerShell Module then open a PowerShell prompt and type “$PSVersionTable” and press enter, verify that PowerShell version 3.0 is listed in the “PSCompatibleVsersions” property

 

 

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34014
BuildVersion                   6.3.9600.16394
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2 

 

Using these instructions you should be able to import the VSC PowerShell module and connect to the VSC. EG

 

 

PS C:\> import-module VSC
PS C:\> Get-Command -Module VSC 

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Cmdlet          Add-VscDatastore                                   VSC
Cmdlet          Add-VscStorageSystem                               VSC
Cmdlet          Connect-VscServer                                  VSC
Cmdlet          Disconnect-VscServer                               VSC
Cmdlet          Get-VscConnectionBroker                            VSC
Cmdlet          Get-VscDatastore                                   VSC
Cmdlet          Get-VscHostList                                    VSC
Cmdlet          Get-VscNasDetails                                  VSC
Cmdlet          Get-VscProvisionableStorageSystem                  VSC
Cmdlet          Get-VscProvisioningPolicyNames                     VSC
Cmdlet          Get-VscSanDetails                                  VSC
Cmdlet          Get-VscStorageSystem                               VSC
Cmdlet          Get-VscStorageSystemId                             VSC
Cmdlet          Get-VscStorageSystemPrivileges                     VSC
Cmdlet          Get-VscTask                                        VSC
Cmdlet          Invoke-VscSpaceReclaim                             VSC
Cmdlet          Mount-VscDatastore                                 VSC
Cmdlet          New-VscClone                                       VSC
Cmdlet          Remove-VscConnectionBroker                         VSC
Cmdlet          Remove-VscDatastore                                VSC
Cmdlet          Remove-VscStorageSystem                            VSC
Cmdlet          Set-VscDatastoreSize                               VSC
Cmdlet          Set-VscDefaultCredentials                          VSC
Cmdlet          Test-VscDatastoreName                              VSC
Cmdlet          Test-VscPolicyBasedProvisioning                    VSC
Cmdlet          Update-VscConnectionBroker                         VSC
Cmdlet          Update-VscStorageSystem                            VSC
Cmdlet          Wait-VscTime                                       VSC

PS C:\> $vsc = "vsc.testlab.local"
PS C:\> $username = "srv_vmware@testlab.local"
PS C:\> $credentials = $host.ui.PromptForCredential("Connect to ""$vsc""", "Please enter the user name and password", $userName, "")
PS C:\> Connect-VscServer -Server $vsc -Credential $credentials
Connected

 

 

Hope this helps!

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

GSMC
6,279 Views

Facing this error 
PS C:\Windows\system32> Import-Module C:\Users\tnaresh\Desktop\NetAppVSC-1.2\NetAppVSC.dll
Get-Command -Module NetAppVSC
Import-Module : Could not load file or assembly
'file:///C:\Users\tnaresh\Desktop\NetAppVSC-1.2\NetAppVSC.dll' or one of its
dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Import-Module C:\Users\tnaresh\Desktop\NetAppVSC-1.2\NetAppVSC.dll
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadExcep
tion
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell
.Commands.ImportModuleCommand

mbeattie
6,269 Views

Hi,

 

Did you follow the solution in this thread? The error you are getting is identical "Operation is not supported. (Exception from HRESULT: 0x80131515)". Search this post for "Module fails to import with error 0x80131515" and follow the steps to unblock the file.

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public