VMware Horizon Community
JMichel974
Enthusiast
Enthusiast
Jump to solution

Issues with virtual machines recompose.

Hi Team,

I have an issue with a cmd script and PS script during virtual machines recompose.

The recompose call the 'post_install.cmd' which is doing action on registry and software (uninstall/install), adding some accounts on the machine : These works, except for the command 'redircmp' :

redircmp "CN=XXX,OU=YY,OU=ZZ,OU=NN,DC=A,DC=B,DC=C,DC=D"

Then, I put this on the cmd to call a Ps script :
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell  -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\XXX\post_install\Move_OU_Exclu.ps1""' -Verb RunAs}"

My PS script  :

$LogTime = Get-Date -Format "dd-MM-yyyy HH-mm-ss"
$LogFile = 'C:\XX\post_install\'+"Move_OU_Exclu_LOG_"+$LogTime+".log"
---------"1 - Part 1 " | Out-File $LogFile -Append -Force
Set-StrictMode -Version 2.0
Set-Location $env:USERPROFILE
$LocUSREnv=(Get-Location)
---------"2 - Capture variable ExecutionPolicy"| Out-File $LogFile -Append -Force
$scopeCuser = (Get-ExecutionPolicy -Scope CurrentUser)
"Variable scopeCuser : $scopeCuser" | Out-File $LogFile -Append -Force
$scopeuserP = (Get-ExecutionPolicy -Scope UserPolicy)
"Variable scopeuserP : $scopeCuser" | Out-File $LogFile -Append -Force
$scopemachine = (Get-ExecutionPolicy -Scope LocalMachine)
"Variable scopemachine : $scopeCuser" | Out-File $LogFile -Append -Force
$scopemachineP = (Get-ExecutionPolicy -Scope MachinePolicy)
"Variable scopemachineP : $scopeCuser" | Out-File $LogFile -Append -Force
$scopeProcess = (Get-ExecutionPolicy -Scope Process)
"Variable scopeProcess : $scopeCuser" | Out-File $LogFile -Append -Force
#Configuration de ExecutionPolicy pour l'utilisateur courant
Set-ExecutionPolicy -Scope CurrentUser Bypass -Force
------------"3 - Variables" | Out-File $LogFile -Append -Force
$ComputerName = ($env:Computername)
"Variable ComputerName : $ComputerName" | Out-File $LogFile -Append -Force
$CurrentUser = ($Env:Username)
"Variable CurrentUser : $CurrentUser" | Out-File $LogFile -Append -Force
$GroupeCible="CSNV_VM-Exclu-Secu-CMCB_GG"
"Variable GroupeCible : $GroupeCible" | Out-File $LogFile -Append -Force
$nme=Get-ADComputer $ComputerName | select -ExpandProperty SamAccountName
"Variable nme : $nme" | Out-File $LogFile -Append -Force
$grp=Get-ADGroup $GroupeCible| select -ExcludeProperty DistinguishedName
"Variable grp : $grp" | Out-File $LogFile -Append -Force
If($grp -like $ComputerName) {
    "OK, Workstation in the AD Group" | Out-File $LogFile -Append -Force
    }
    Else {
        Try{
            "Start adding workstation $ComputerName in AD Group $GroupeCible" | Out-File $LogFile -Append -Force
            Add-ADGroupMember -Identity $GroupeCible -Members $nme -Server "XXXXXX" -ErrorAction Stop
            }
            catch{
$boolError = $true
$strError = $_
"Machine $ComputerName operation for AD Group $GroupeCible retour:$strError" | Out-File $LogFile -Append -Force
$global:BoolAtLeastOneError = $true
    }
        }
set-ExecutionPolicy -Scope CurrentUser $scopeCuser -Force

But when it runs my command calling PS, the account running the PS script isn't the good one (it was the machine account).

In fact, some colleagues told me it was a service account that ran the script but after returning my log, it turns out to be the machine account or the local admin account.

That's why my script can't move the machine into the AD group.

My goal is to add my workstation into the AD group or to run my script with a domain account.

I tried to run immediatly my PS script during the recompose without running the cmd, and now it's the local admin account which is used.

I don't get it at all. And I'm restricted with my rights.

I hope you understand what I mean.

If you know the process exact of recompose, I will be glad to know it and to know what account is used for the recompose.

Thank you all.

Regards,

1 Solution

Accepted Solutions
techguy129
Expert
Expert
Jump to solution

Here is the official documentation on quickprep scripts:

Running QuickPrep Customization Scripts

A.) You cannot change the account as per the documentation

QuickPrep Script Account

QuickPrep runs the scripts under the account under which the VMware View Composer Guest Agent Server service is configured to run. By default, this account is Local System.

Do not change this log on account. If you do, the linked clones do not start.

B.) Have you considered running the Add-ADGroupMember with the -Credentials command to give you access?

C.) Based on the error you posted, it seems your powershell command isn't working correctly. Unless you have a specific reason I would short it to

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\XXX\post_install\Move_OU_Exclu.ps1"

View solution in original post

6 Replies
JMichel974
Enthusiast
Enthusiast
Jump to solution

I've got this error code :

2018-03-05 09:19:39,043 [1592] INFO  Ready  -  [Ready.cpp, 128] Running the PostSync script: "C:\XXXX\post_install\Move_OU_Exclu.ps1" with timeout: 20000

2018-03-05 09:19:39,043 [1592] DEBUG Wow64FsRedirectionOff  -  [Wow64FsRedirectionOff.cpp, 109] Successfully disabled WOW FS redirection.

2018-03-05 09:19:39,073 [1592] FATAL Guest  -  [Guest.cpp, 462] RunScript: Unable to execute script: 0028D250 , error = 193

2018-03-05 09:19:39,073 [1592] DEBUG Wow64FsRedirectionOff  -  [Wow64FsRedirectionOff.cpp, 135] Successfully reverted WOW FS redirection.

2018-03-05 09:19:39,100 [1592] FATAL Ready  -  [Ready.cpp, 141] Failed to run PostSyncScript: "C:\XXXX\post_install\Move_OU_Exclu.ps1"Unable to create process for the scriptError 193 (0xc1): %1 n’est pas une application Win32 valide.

Regards,

Michel

0 Kudos
JMichel974
Enthusiast
Enthusiast
Jump to solution

Is it possible to choose the account that will run in the quickprep?

Regards,

Michel

0 Kudos
techguy129
Expert
Expert
Jump to solution

Here is the official documentation on quickprep scripts:

Running QuickPrep Customization Scripts

A.) You cannot change the account as per the documentation

QuickPrep Script Account

QuickPrep runs the scripts under the account under which the VMware View Composer Guest Agent Server service is configured to run. By default, this account is Local System.

Do not change this log on account. If you do, the linked clones do not start.

B.) Have you considered running the Add-ADGroupMember with the -Credentials command to give you access?

C.) Based on the error you posted, it seems your powershell command isn't working correctly. Unless you have a specific reason I would short it to

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\XXX\post_install\Move_OU_Exclu.ps1"

JMichel974
Enthusiast
Enthusiast
Jump to solution

Hi Techguy,

Thank you for your answer.

I made some changes.

I did a script RunAs :

$args = "C:\XXXX\post_install\Move_OU_Exclu.ps1"

Start-Process powershell.exe -Credential $Credential -ArgumentList ("-file $args")

And now in the : vmware-viewcomposer-ga-new.log.

I have this error :

2018-03-05 17:59:47,161 [1944] INFO  Guest  -  [Guest.cpp, 513] Script "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" C:\XXX\post_install\post_install.ps1 error ouput: Start-

Process: Can not execute this command because of the error:

Access denied

At the character C:\XXX\post_install\post_install.ps1: 18: 1

+ Start-Process powershell.exe -Credential $Credential -ArgumentList ("-file $args ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~

    + CategoryInfo          : InvalidOperation : (:) [Start-Process], InvalidOperationException

    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

I need to check with another service if the account my colleague gave me has the correct rights.

But I will try your B) and C) suggestions.

Regards,

Michel

0 Kudos
JMichel974
Enthusiast
Enthusiast
Jump to solution

Techguy,

I tried your B) suggestion and it works fine when I run the command on PS ISE.

But when I run the recompose I have this :

2018-03-06 14:50:01,566 [1952] INFO  Ready  -  [Ready.cpp, 128] Running the PostSync script: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" C:\XXX\post_install\post_install.ps1 with timeout: 120000

2018-03-06 14:50:01,566 [1952] DEBUG Wow64FsRedirectionOff  -  [Wow64FsRedirectionOff.cpp, 109] Successfully disabled WOW FS redirection.

2018-03-06 14:52:02,795 [1952] FATAL Guest  -  [Guest.cpp, 529] script "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" C:\XXX\post_install\post_install.ps1 timed out

Best regards,

Michel

0 Kudos
JMichel974
Enthusiast
Enthusiast
Jump to solution

Well,

I've put 120 000 milliseconds the first time and it returned TimedOut.

But the second time, the script has been executed correctly.

To be safe, I modify it to 600 000 milliseconds. I think everything is working well now. I'm doing a test again to be sure but it should be alright.

Thanks again.

Best regards,

Michel

0 Kudos