Forum Discussion
JamesA1005
Oct 07, 2024Copper Contributor
Azure scheduled task powershell script not running on remote app but runs on full desktop
Hello, Just wondering if anyone has any thoughts or can help. I am running a powershell script to map a drive on an azure virtual desktop. The script will map the drive if I log in to a full desktop...
Kidd_Ip
Oct 07, 2024MVP
Try below script includes logging, please make sure fully understand the script before apply:
$logFile = "C:\logfile.txt"
try {
Add-Content -Path $logFile -Value "Starting drive mapping at $(Get-Date)"
New-PSDrive -Name "X" -PSProvider FileSystem -Root "\\yourstorageaccount.file.core.windows.net\yourfileshare" -Persist -Credential (Get-Credential)
Add-Content -Path $logFile -Value "Drive mapping successful at $(Get-Date)"
} catch {
Add-Content -Path $logFile -Value "Error during drive mapping: $_"
}
- JamesA1005Oct 08, 2024Copper ContributorHi I am currently running the script that MS provides. I have tried both the AD and key scripts, They both work for the full desktop but not the remote app. I cant see much difference in running the other script, maybe just for error logs?
$connectTestResult = Test-NetConnection -ComputerName fiesharename.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
# Save the password so the drive will persist on reboot
cmd.exe /C "cmdkey /add:`"filesharename.file.core.windows.net`" /user:`"localhost\oscarexports`" /pass:`"Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==`""
# Mount the drive
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\filesshare.file.core.windows.net\oscarexports" -Persist
} 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."
}