locked
Add vMware VM to Domain Using Invoke-VMScript not working RRS feed

  • Question

  • Hello all,

    I put together this script to add a newly created VM from a template to our domain but I"m getting an error at the Invoke-VMScript line.  Can you review and let me know what I might be doing wrong?

    My Script is:

    Add-PSSnapin VMware.VimAutomation.Core
    Import-Module ActiveDirectory
    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session
    Connect-VIServer vc-server.mydomain.com
    
    $domainName = "mydomain"
    
    $password = "mypassword" 
    
    $password = ConvertTo-SecureString -String $securepassword -AsPlainText -Force 
    
    $username = "$domainName\myloginid" 
    
    $cred = New-Object System.Management.Automation.PSCredential($username,$password)
    
    Invoke-VMScript  -VM guestname -GuestUser admin -GuestPassword localpw -ScriptType Powershell -ScriptText "Add-Computer -ComputerName vmname -Credential $cred -Restart -Force" -Verbose
    


    The error I get is:

    Invoke-VMScript  -VM vmname -GuestUser admin -GuestPassword localpw -ScriptType Powershell -ScriptText "Add-Computer -ComputerName vmname -Credential $cred -Restart -Force" -Verbose

    VERBOSE: 10/13/2017 4:16:56 PM Invoke-VMScript Started execution
    VERBOSE: Performing the operation "Invoke-VMScript" on target "vmname".
    VERBOSE: 10/13/2017 4:16:59 PM Invoke-VMScript Finished execution

    ScriptOutput
    -----------------------------------------------------------------------------------------------------------------------|  Add-Computer : Cannot process argument transformation on parameter 
    |  'Credential'. Access is denied
    |  At line:1 char:55
    |  + ... d002011 -Credential System.Management.Automation.PSCredential -Restar ...
    |  +                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      + CategoryInfo          : InvalidData: (:) [Add-Computer], ParameterBindin 
    |     gArgumentTransformationException
    |      + FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.P 
    |     owerShell.Commands.AddComputerCommand
    |   
    |  
    -----------------------------------------------------------------------------------------------------------------------

    Thanks in advance for any assistance you can give.  

    Friday, October 13, 2017 8:33 PM

All replies

  • For VMWare please post in VMWare forum.

    https://code.vmware.com/forums?id=2530


    \_(ツ)_/

    Friday, October 13, 2017 8:44 PM
  • Hi,

    Based on the current situation, this error message may be related to credentials. Please have a try to modify the scripts to see if the issue still remains, for your reference:
    $domainName = "mydomain"
    $securepassword = "mypassword" 
    $password = ConvertTo-SecureString -String $securepassword -AsPlainText -Force 
    $username = "$domainName\myloginid"
    $cred = New-Object System.Management.Automation.PSCredential($username,$password)

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, October 16, 2017 8:51 AM
  • Hi,

    Just checking in to see if the information provided was helpful. Does the script work?

    Please let us know if you would like further assistance.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, October 19, 2017 9:14 AM
  • Hi,

    I am checking how the issue is going, if you still have any questions, please feel free to contact us.

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.

    Appreciate for your feedback.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, October 24, 2017 2:18 AM