Unable to map Azure file share

I’ve been trying for days to figure out how to get an Azure file share mapped to the VM being built by packer. Everything I’ve found points to using New-PSDrive, but that has continued to fail.

This is, among many other things, what I’ve recently tried:

provisioner "powershell" {
    inline = [
      "cmd.exe /C \"cmdkey /add:`\"<storage_account>.file.core.windows.net`\" /user:`\"localhost\\<storage_account>`\" /pass:`\"<access_key>`\"\"",
      "New-PSDrive -Name F -PSProvider FileSystem -Root \\\\<storage_account>.file.core.windows.net\\fileshare -Persist -Scope Global"

No matter what I’ve attempted, I get

CMDKEY: Credentials cannot be saved from this logon session.


New-PSDrive : The network resource type is not correct

These commands work when I execute them locally in either Powershell 5.x or Powershell Core 7.x.

I’ve also tried defining credentials to pass to the New-PSDrive cmdlet. That also hasn’t worked.