如何运行Azure的VM CustomScriptExtension作为域用户? (第1部分) [英] How to run Azure VM CustomScriptExtension as domain user? (part 1)

查看:143
本文介绍了如何运行Azure的VM CustomScriptExtension作为域用户? (第1部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么工作是一个PowerShell脚本,需要一个JSON文件来创建一个新的虚拟机; JSON文件包含说明虚拟机加入域并运行自定义脚本。这两个事情发生,但是脚本运行的用户工作组\\ SYSTEM ,因此无法访问网络驱动器。

What I have working is a Powershell script that takes a JSON file to create a new VM; the JSON file contains instructions for the VM to join a domain and run a custom script. Both things do happen, but the script runs as the user workgroup\system and therefore doesn't have access to a network drive.


  • 上市是否扩展按照这个顺序的保证的脚本运行的之后的加入域完成(或者是偶然的)?

  • Does listing the extensions in this order guarantee that the script runs after the domain join is complete (or is it haphazard)?

有什么我可以做,以确保该脚本不运行,直到加入域完成?我怎样才能最好的检测(从本地新VM)的加入域完成?你会如何​​延迟的脚本的运行,直到一个更好的时间(像一个一次性的cron作业)?

Is there something I can do to ensure that the script does not run until the domain join is complete? How can I best detect (locally from the new VM) that the domain join is complete? How would you delay the running of the script until a better time (something like a once-off cron job)?

更新:在两个分割的问题,另一半则是这里

Update: Split question in two, other half is here.

此外,巨大的感谢应用于黛维·琼斯了一个多小时的互动支持。我通过能够给只有一个对勾回报感激。

Also, immense thanks to Dewi Jones for more than an hour of interactive support. I'm indebted by being able to give only a single check mark in return.

推荐答案

获取域名,如果域名等于要加入再继续之一。

Get the domain and if the domain is equal to the one you are joining then continue.

$domain = gc env:UserDNSDomain

While ($domain -neq "FQDN")
{
Start-Sleep -seconds 2
}

否则,可以使用凭据,如下所示调用脚本

Otherwise you can call a script using credentials as follows

$username = 'user'
$password = 'password'
$PSArgs = 'Script file name'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process Powershell.exe -Credential $credential $PSArgs

这篇关于如何运行Azure的VM CustomScriptExtension作为域用户? (第1部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆