i am trying to add servers to the domain, but with no luck, i tried to concatenate the command and still no luck
i appreciate your input on where i am going wrong
$vmname="testdomain.xyz.com"
$Localcred = Get-Content C:\SAMIs\User\local.txt |ConvertTo-SecureString -Key (1..32)
$dom_encrypted = Get-Content C:\SAMIs\User\Domcred.txt |ConvertTo-SecureString -Key (1..32)
$DomCred = New-Object System.Management.Automation.PsCredential -ArgumentList 'user@xyz.com', $dom_encrypted
$Lcredentials = New-Object System.Management.Automation.PsCredential -ArgumentList 'localadmin', $Localcred
$x= 'Add-computer -domainname $domain -credential $DomCred -computername $vmname -localcredential $Lcredentials -restart -Verbose'
$domain = "XXXXXXX"
write-host "$x" -Verbose
$addtodomain = @'
$x
'@
Invoke-VMScript -VM $vmname -ScriptText $addtodomain -GuestUser $Lcredentials.UserName -GuestPassword $Lcredentials.Password -Verbose
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ScriptOutput
-----------------------------------------------------------------------------------------------------------------------|
-----------------------------------------------------------------------------------------------------------------------
This is again a string substitution issue.
You are creating objects (PSCredential) on the local machine, which you then refer to in the code executed in the VM.
That will not work.
A better way would be to calculate those objects inside the VM.
That way you only have to pass/substitute strings in the code.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is again a string substitution issue.
You are creating objects (PSCredential) on the local machine, which you then refer to in the code executed in the VM.
That will not work.
A better way would be to calculate those objects inside the VM.
That way you only have to pass/substitute strings in the code.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference