PowerCLI

 View Only
  • 1.  Powercli cmdlet is not working

    Posted Nov 20, 2014 04:11 AM

    Hi All,

    (I Have connected to VI Server)When I am trying to execute below command

    get-datastore | get-datastoremountinfo | where {$_.State -eq "error"} | select-object Datastore,VMhost | FT -AutoSize

    I am getting Error as

    get-datastoremountinfo: The term 'get-datastoremountinfo' is not recognized as the name of a cmdlet, function, script file, or operable Program, Check the spelling of the name, or if a path was included, verify the path is correct and try again.

    I am using powercli Version 5.0.1 Build 1992769 & Powershell Version 4.0 Build 6.3.9600.16406.

    When I am trying to execute add-pssnapin VMware.vimautomation.core it is showing that it is already added.

    Please suggest why this cmdlet is behaving like this.



  • 2.  RE: Powercli cmdlet is not working

    Posted Nov 20, 2014 04:40 AM

    Hello, Sivaramsharmar-

    You are getting that as the function that you are calling, "Get-DatastoreMountInfo", is not a cmdlet in a PowerCLI snapin.  It is a function provided to the community by lamw and alanrenouf.  The original doc is available at https://communities.vmware.com/docs/DOC-18008, and I posted an updated version at https://communities.vmware.com/message/2408628#2408628.

    In order to use that function, you need to grab on of the versions of those functions and define them in your PowerShell session.  For example, download the .ps1 file, and then dot-source it to define the functions, like:

    ## dot-source the ps1 file (yes, including the leading dot and space characters)
    . C:\temp\DatastoreFunctions-updatedJun2014.ps1

    You can then use the Get-DatastoreMountInfo function.  Make sense?

    Unrelated:  you might consider grabbing the latest PowerCLI version from vmware.com/go/powercli -- the current version is v5.8r1.



  • 3.  RE: Powercli cmdlet is not working

    Posted Nov 20, 2014 07:20 AM

    Hi Mattboren, I have gone through this link https://communities.vmware.com/docs/DOC-18008, I have tried to execute the same command "get-datastore | get-datastoremountinfo | sort datastore,  VMhost | FT -AutoSize" Still I was not able to . Is there any way to execute this command without executing .ps1 Script. Please let me know. Thanks in Advance Regards, Siva



  • 4.  RE: Powercli cmdlet is not working

    Posted Nov 21, 2014 03:39 AM

    Hello-

    The need is to define that function, Get-DatastoreMountInfo, in the PowerShell session in which you intend to use it.  Dot-sourcing the PS1 file with the function definitions is not the only way:  you can add the function definition to any of the profiles that load when you start up your PowerShell session, you can copy the function definition to your clipboard and then paste it into your PowerShell session, etc.

    The point:  in order to use the function, it must be defined in your current PowerShell session.  Until it is defined in the session, you cannot call the function.  So:  define it in you session in some way, _then_ use it and feel the joy!