Forum Discussion
Map network drive
The screenshot isn't overly-useful as we need to see more from line 25 downwards, to at least as far as where the drive mapping is being actioned.
What doesn't add up in the screenshot is the reference to the %username% in the error. That's an environment variable from DOS not PowerShell. It makes sense that kind of reference won't work (at least not in a PowerShell session) which in turn validates the error message about "path not found", but what is less clear through not enough of the script being visible to us is how it got to that point.
That fact that in the second iteration of the command you were able to map the drive successfully suggests (but doesn't guarantee) that permissions aren't the issue, despite the suggestion within the error text. You could verify that via klist but that's getting too far off the beaten track this early in the piece.
If the home drive path is actually being pulled from something like the "homeDirectory" attribute from the on-premise Active Directory user account rather than the JSON (which is what we're guessing is the driver, but then that doesn't explain %username% cropping up in the error message) then you'd need to use a "-replace" PowerShell RegEx (or equivalent) to replace "%username%" with PowerShell's equivalent, "$env:username". But now I'm just wildly guessing because we can't see what we need to get ourselves informed.
If you can paste more relevant parts of the script, we can probably be of more use than we are at the moment.
Cheers,
Lain