I've been working on a script to setup a dc and forest using PowerCLI. I've got the script working fine but its throwing the below error.
VERBOSE: Configuring AD Forest on testvmdc
Invoke-VMScript : 1/27/2020 10:39:56 PM Invoke-VMScript A general system error occurred: vix error codes = (3016, 0).
At C:\Scripts\Dev\Create-DomainController_DEV_Jay.ps1:88 char:1
+ Invoke-VMScript -ScriptText $ConfigureNewDomain -VM $DomainController ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], SystemError
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_GetProcessOutputInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
I'm trying to figure out why I'm getting the error when it does not appear to effect the script.
Here's the script so for. I'm sure It's pretty ugly lol
$DomainControllerVMName = "testvmdc"
# ------This Section Sets the Credentials to be used to connect to Guest VMs that are NOT part of a Domain------
# NOTE - Make sure you input the local credentials for your domain controller virtual machines below. This is used for logins prior to them being promoted to DCs.
# This should be the same local credentials as defined within the template that you are using for the domain controller VM.
$DCLocalUser = "$DomainControllerVMName\administrator"
$DCLocalPWord = ConvertTo-SecureString -String "P@ssword" -AsPlainText -Force
$DCLocalCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $DCLocalUser, $DCLocalPWord
# The below credentials are used by operations below once the domain controller virtual machines and the new domain are in place. These credentials should match the credentials
# used during the provisioning of the new domain.
$DomainUser = "TEST\administrator"
$DomainPWord = ConvertTo-SecureString -String "P@ssword" -AsPlainText -Force
$DomainCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $DomainUser, $DomainPWord
$DCLocalCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $DCLocalUser, $DCLocalPWord
#####network Config######
# Domain Controller VM IPs Below
# NOTE: Insert IP info in IP SubnetMask Gateway Order
# NOTE: For the purposes of this script we do not define static DNS settings for this single DC VM as it will point to itself for DNS after provisioning of the new domain.
# You could add an additional netsh line below to assign static DNS settings in the event you need to do so. See the File Server Section below for further details.
$DCNetworkSettings = 'netsh interface ip set address "Ethernet0" static 172.69.0.20 255.255.255.0 172.69.0.254'
Write-Verbose -Message "Getting ready to change IP Settings on VM $DomainControllerVMName." -Verbose
Invoke-VMScript -ScriptText $DCNetworkSettings -VM $DomainControllerVMName -GuestCredential $DCLocalCredential
# NOTE - The Below Sleep Command is due to it taking a few seconds for VMware Tools to read the IP Change so that we can return the below output.
# This is strctly informational and can be commented out if needed, but it's helpful when you want to verify that the settings defined above have been
# applied successfully within the VM. We use the Get-VM command to return the reported IP information from Tools at the Hypervisor Layer.
Start-Sleep 30
$DCEffectiveAddress = (Get-VM $DomainControllerVMName).guest.ipaddress[0]
Write-Verbose -Message "Assigned IP for VM [$DomainControllerVMName] is [$DCEffectiveAddress]" -Verbose
#####Domain config##########
# This Command will Install the AD Role on the target virtual machine.
$InstallADRole = 'Install-WindowsFeature -Name "AD-Domain-Services" -Restart'
Write-Verbose -Message "Installing AD Roles on $DomainControllerVMName" -Verbose
Invoke-VMScript -ScriptText $InstallADRole -VM $DomainControllerVMName -GuestCredential $DCLocalCredential
Write-Verbose -Message "AD Roles have been installed on $DomainControllerVMName" -Verbose
#Install DNS Roles
Write-Verbose -Message "Installing DNS Roles on $DomainControllerVMName" -Verbose
# This section installs the DNS roles
$InstallDNSRole = 'Install-WindowsFeature -Name DNS -IncludeAllSubFeature -IncludeManagementTools'
Invoke-VMScript -ScriptText $InstallDNSRole -VM $DomainControllerVMName -GuestCredential $DCLocalCredential
#Invoke-VMScript -ScriptText 'Install-WindowsFeature -Name DNS -IncludeAllSubFeature -IncludeManagementTools' -VM TestVMDC -GuestCredential $DCLocalCredential
Write-Verbose -Message "DNS Roles have been installed on $DomainControllerVMName" -Verbose
# Configure Domain
# This Scriptblock will define settings for a new AD Forest and then provision it with said settings.
# NOTE - Make sure to define the DSRM Password below in the line below that defines the $DSRMPWord Variable!!!!
$ConfigureNewDomain = 'Write-Verbose -Message "Configuring Active Directory" -Verbose;
$DomainMode = "WinThreshold";
$ForestMode = "WinThreshold";
$DomainName = "Test.local";
$DSRMPWord = ConvertTo-SecureString -String "P@ssword" -AsPlainText -Force;
Install-ADDSForest -ForestMode $ForestMode -DomainMode $DomainMode -DomainName $DomainName -InstallDns -SafeModeAdministratorPassword $DSRMPWord -Force'
Write-Verbose -Message "Configuring AD Forest on $DomainControllerVMName" -Verbose
Invoke-VMScript -ScriptText $ConfigureNewDomain -VM $DomainControllerVMName -GuestCredential $DCLocalCredential | Out-Null
# Script Block for configuration of AD automatically reboots the machine after provisioning
Write-Verbose -Message "Rebooting $DomainControllerVMName to Complete Forest Provisioning" -Verbose
# Below sleep command is in place as the reboot needed from the above command doesn't always happen before the wait-tools command is run
Start-Sleep -Seconds 60
Wait-Tools -VM $DomainControllerVMName -TimeoutSeconds 300
Write-Verbose -Message "Installation of Domain Services and Forest Provisioning on $DomainControllerVMName Complete" -Verbose
#This section installs AD Tools
Write-Verbose -Message "Installing AD Tools on $DomainControllerVMName" -Verbose
$InstallADtools = 'ADD-WindowsFeature RSAT-Role-Tools'
Invoke-VMScript -ScriptText $InstallADtools -VM $DomainControllerVMName -GuestCredential $DomainCredential
Write-Verbose -Message "Install of AD Tools on $DomainControllerVMName completed" -Verbose
#Create SHORTCUTS
# Create Active directory Users and Computers shortcut on the public desktop
Write-Verbose -Message "Creating Active directory Users and Computers Desktop shortcut on $DomainControllerVMName" -Verbose
$ADshortcut = '
$SourceFileLocation = "$env:SystemRoot\System32\dsa.msc"
$ShortcutLocation = "C:\Users\Public\Desktop\Active directory Users and Computers.lnk"
#New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
#-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
#Save the Shortcut to the TargetPath
$Shortcut.Save() '
Invoke-VMScript -ScriptText $ADshortcut -VM $DomainControllerVMName -GuestCredential $DomainCredential | Out-Null
Write-Verbose -Message "Done Creating Active directory Users and Computers Desktop shortcut on $DomainControllerVMName" -Verbose
# Create DNS on the public desktop
Write-Verbose -Message "Creating DNS Desktop shortcut on $DomainControllerVMName" -Verbose
$DNSshortcut = '
$SourceFileLocation = "$env:SystemRoot\System32\dnsmgmt.msc"
$ShortcutLocation = "C:\Users\Public\Desktop\DNS.lnk"
#New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
#-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
#Save the Shortcut to the TargetPath
$Shortcut.Save() '
Invoke-VMScript -ScriptText $DNSshortcut -VM $DomainControllerVMName -GuestCredential $DomainCredential | Out-Null
Write-Verbose -Message "Done creating DNS Desktop shortcut on $DomainControllerVMName" -Verbose