Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在azure中创建一个没有临时存储驱动器的vm?_Azure_Powershell_Azure Cli_Azure Cli2 - Fatal编程技术网

有没有办法在azure中创建一个没有临时存储驱动器的vm?

有没有办法在azure中创建一个没有临时存储驱动器的vm?,azure,powershell,azure-cli,azure-cli2,Azure,Powershell,Azure Cli,Azure Cli2,我使用此命令启动虚拟机: az vm create -n $virtualMachine -g $resourceGroup --size Standard_D2_v3 --image win2016datacenter --data-disk-sizes-gb 40 --location $location --admin-username $admin --admin-password $password 每次它创建一个名为“临时存储”的驱动器D时,我有没有办法摆脱这个驱动器 注:我知道它

我使用此命令启动虚拟机:

az vm create -n $virtualMachine -g $resourceGroup --size Standard_D2_v3 --image win2016datacenter --data-disk-sizes-gb 40
--location $location --admin-username $admin --admin-password $password
每次它创建一个名为“临时存储”的驱动器D时,我有没有办法摆脱这个驱动器


注:我知道它的剂量,我不需要它。

不幸的是,所有Azure虚拟机至少有两个磁盘,一个是操作系统磁盘,另一个是临时磁盘。临时磁盘随VM大小而来。您可以看到带有临时存储的回显


因此,如果没有临时磁盘,就无法创建VM。您需要考虑的是如何根据驱动器号的需要更改应用程序。例如,将磁盘需求更改为驱动器号E。

我提出了以下解决方案:

$resourceGroup = "your resource group name"
$virtualMachine = "your virtual machine name"

# remove page file from drive d
az vm run-command invoke -g $resourceGroup -n $virtualMachine --command-id RunPowerShellScript --scripts '$CurrentPageFile = Get-WmiObject -Query "select * from Win32_PageFileSetting"; $CurrentPageFile.delete(); Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{name="c:\pagefile.sys";InitialSize = 0; MaximumSize = 0}; Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\cdrom -Name Start -Value 4 -Type DWord'

# restart server
az vm restart -g $resourceGroup -n $virtualMachine

# set drive d and it's related disk into offline mode
az vm run-command invoke -g $resourceGroup -n $virtualMachine --command-id RunPowerShellScript --scripts 'get-disk -Number (Get-Partition -DriveLetter D).disknumber | Set-Disk -IsOffline $true'

# get azure disks and initialize, format and label it (assign a drive letter as well)
az vm run-command invoke -g $resourceGroup -n $virtualMachine --command-id RunPowerShellScript --scripts 'Get-Disk | Where partitionstyle -eq "raw" | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "disk2" -Confirm:$false'
正如@Charles Xu所说,你不能删除它,但你可以忽略它并使其离线。 我花了很长时间才弄明白,但这可能会从别人那里节省一些时间

如果您只需要powershell,这就是它:

$CurrentPageFile = Get-WmiObject -Query "select * from Win32_PageFileSetting"; 
$CurrentPageFile.delete(); 
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{name="c:\pagefile.sys";InitialSize = 0; MaximumSize = 0};
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\cdrom -Name Start -Value 4 -Type DWord
# you need to restart at this stage
get-disk -Number (Get-Partition -DriveLetter D).disknumber | Set-Disk -IsOffline $true
Get-Disk | Where partitionstyle -eq "raw" | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "disk2" -Confirm:$false
日期:2021年2月18日 Azure虚拟机大小没有本地临时磁盘,现在可以了

Afaik这对于Azure虚拟机是强制性的。所以我认为你必须接受它。问题是什么?我有一个应用程序应该使用驱动器D,驱动器D必须为1TB,所以我不能使用这个临时存储,因为数据可能会从itHmmm中删除。。。哇!您可以与该应用程序的供应商联系,要求将该应用程序适应21世纪。;-:-相信我,你不能搞乱他们…不管是他们还是微软。。。没有那么多选择。。。你的选择。;-)我为你感到抱歉。看来你是对的,但我的问题是如何摆脱它,有没有办法移除驱动器?@EhsanZargarErshadi不,你不能移除它。但如果需要,您可以在创建虚拟机后更改驱动器号。我同意这是有帮助的,但不幸的是,这并不是问题的答案,如果我接受它作为答案,可能会误导其他人,我已经添加了解决方法。事实上,你会得到我的投票。