如何以管理员身份在Azure Windows VM上运行Powershell命令

时间:2019-07-10 15:46:47

标签: azure-devops powershell-4.0

我正在尝试创建azure Windows 2012 r2服务器虚拟机,并使用Python SDK和Powershell在该计算机上安装SQL Server和Microsoft SQL Reporting Services。 我可以使用python SDK创建Windows计算机,无需登录计算机即可安装Microsoft SQL Server。

但是,使用远程Powershell脚本在Azure Windows虚拟机上安装Microsoft SQL Reporting Services我必须至少登录一次,才能通过远程脚本安装这些服务。如果我不登录,所有脚本都会失败。

我感觉问题出在Powershell的执行策略上。

有人可以指导我如何以管理员身份在azure Windows VM上运行powershell命令而无需一次登录计算机吗? 或如何在不一次登录Microsoft Azure Windows虚拟机的情况下将powershell执行策略设置为remotesigned?

我能够创建虚拟机,并通过Python SDK自动安装sql server。如果使用Remote powershell命令至少登录一次,还可以安装SSRS。 但是我没有登录Powershell脚本抛出“ shell无法启动” 登录虚拟机后,该问题得到解决,远程脚本运行正常

这将安装SSRS

SQLServerReportingServices.exe / quiet / norestart / IAcceptLicenseTerms / PID = $ productId

这将在VM上配置SSRS

function Get-ConfigSet()
{
    return (Get-WmiObject -namespace 'root\Microsoft\SqlServer\ReportServer\RS_SSRS\v14\Admin' -class MSReportServer_ConfigurationSetting -ComputerName localhost)
}

# Allow importing of sqlps module
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force

# Retrieve the current configuration
$configset = Get-ConfigSet

$configset
if(!$configset.isInitialized)

我正在使用paexec通过创建虚拟机时使用的用户名和密码远程运行这些脚本。

我希望这无需登录计算机即可解决,因为我们要部署多个解决方案,并且无法登录到每次部署的精巧虚拟机中才能成功

0 个答案:

没有答案