首页 > 解决方案 > 如何使用自定义脚本扩展从 Azure 激活 Windows 上的网络驱动器?

问题描述

我正在尝试在创建后立即将网络驱动器(azure 文件共享)添加到 azure windows vm。我想自动化它,所以我使用自定义脚本扩展,但我遇到了一些问题。网络驱动器是为 Azure FileShare 创建的。下面是允许我添加驱动器文件共享的代码:

$connectTestResult = Test-NetConnection -ComputerName mystorage.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
    # Save the password so the drive will persist on reboot
    cmd.exe /C "cmdkey /add:`"$mystorage.file.core.windows.net`" /user:`"Azure\$mystorage`" /pass:`"$mykey`""
    # Mount the drive
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\$mystorage.file.core.windows.net\$mydrive" -Persist -Scope Global 
} else {
    Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."
}

Net Use

此脚本在从终端手动执行并执行包含此代码的 script.ps1 文件时工作正常。但是在使用自定义脚本扩展时它不起作用,驱动器显示为断开的网络驱动器 (Z:)

任何想法?

标签: windowsazurenetwork-driveazure-storage-filesazure-vm

解决方案


推荐阅读