grisha
grisha

Reputation: 399

Create AD Users with Custom Script Extension

Is it possible to create AD Users (and generally run AD cmdlets) with Custom Script Extension on Azure machines?

I see that CSE is running as SYSTEM. It also doesn't start any scripts that I am trying to run as a different user, e.g.

#try1
Start-Process Powershell.exe -ArgumentList C:\MyScript.ps1 -Credential $VMcred

#try2
$farmSession = New-PSSession -Credential $VMcred -ComputerName $env:computername            
Invoke-Command -Session $farmSession -Script `
{ #MyScriptHere}

Is the solution to assign AD permissions to a SYSTEM account?
Or PSRemoting is a must in this case?

Upvotes: 0

Views: 290

Answers (1)

Sa Yang
Sa Yang

Reputation: 9411

I think your scripts won't work. Since the Custom Script Extension is running as a System account, you cannot change it running as another different user.

Solution:

First, you can run the regular powershell cmdlets with Custom script extension. But you will failed with it, Then you should RDP to your VM and find the error massage in the Event Viewer. Then you can follow this blog to assign permissions to System account.

After assigning permissions, you will succeed running the same powershell cmdlets with Custom script extension.

By the way, I don't understand why you need CSE to add ad users for your DC on Azure VM. Why not just add it by RDP the VM and run powershell or else. Custom script extension is usually used for some tasks when user cannot RDP the VM .

Upvotes: 2

Related Questions