问题描述
我正在尝试在创建后立即将网络驱动器(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:)
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)