I wish to attach a network drive/share from a session created via sshd. The drive was originally created with the standard Powershell connect script provided on the "Connect" tab as executed in a Powershell window in RDP. The drive persists and the W2022 instance can be stopped and restarted and Z: drive reappears in Powershell windows launched inside RDP. My question concerns connecting to Z: from shells launched from sshd.
The command
net use Z: \\myStorageAcct.file.core.windows.net\xfer /user:myStorageAcct
prompts for a password and I enter the storage account secret key -- which starts with a slash -- and everything works. The net use command can take the password on the command line but I cannot figure out how to pass the password without net use interpreting the password as an option, e.g.:
net use Z: \\myStorageAcct.file.core.windows.net\xfer /user:myStorageAcct /CMA33FV...==
The option /CMA33FV...== is unknown
I am open to Powershell tricks or a util other than net use to attach the drive.
EDIT
Important constraint: Sessions created with sshd cannot use the standard Powershell script that appears in the "Connect" tab of the file share. In particular, the cmdkey exec produces this error:
CMDKEY: Credentials cannot be saved from this logon session.



Logging in with either name+password or a keypair via
sshdyields a restricted session that requires additional authentication to access remote resources. One way or another, you will have to provide credentials to attach the drive. These can be supplied in a script, the environment, a key vault, etc. but the essence of the solution is:By specifying a credential object,
New-PSDriveavoids the leading slash problem encountered withnet usewhere the password is mistaken for an option.