Windows 10 script to ask credentials for non-persistent webdav map

Long story short, multiple users need to share a single Windows 10 account. Upon login I would like the user to be asked their nextcloud username and password and a non-persistent webdav mapped drive be created. I have tried this powershell script and it works but it only for Admin users. Can anyone help me understand why it won’t run for a non-admin user? In the same script if I put a simple echo test, it does work.

$credential = $host.ui.PromptForCredential("NextCloud credentials", "Please enter your user name and password for nextcloud.", "","")
$username = $credential.UserName
[String]$WebDAVShare = "\\nextcloud.mysite.com@SSL\remote.php\dav\files\$username\"
New-PSDrive -Name "O" -Root $WebDAVShare -PSProvider FileSystem -Credential $credential -Scope Global 
net use O: $WebDAVShare
exit