I'm working on a user transfer script and need to retrieve the mapped network drive paths for users to transfer to a new computer. I noticed that the command "net use" fetches this data in around 50 milliseconds, while "Get-SmbMapping" can take anywhere from 5 to 30 seconds for the same information. I'm really curious about why there's such a significant difference in speed. Am I using "Get-SmbMapping" incorrectly?
5 Answers
Basically, PowerShell prioritizes utility over speed. It’s great for complex tasks but can be slower than specialized tools like the "net" command. So, yeah, enjoy the ease of PowerShell but sometimes those faster tools will be your best bet!
The reason you're seeing such a speed difference is that "Get-SmbMapping" uses WMI, which can often be slow. You might want to try using `Get-PSDrive -PSProvider FileSystem | Where-Object {$_.DisplayRoot -match '^\'}` as it tends to be a bit faster. Just keep in mind it won't work if the drives are disconnected, and sometimes it adds extra formatting to the paths that can be annoying.
The "net" command was designed for use in earlier operating systems like DOS, which is why it's faster. In contrast, PowerShell incorporates a lot of layers which slow it down. If it's performance you need, sticking with tools like "net" can be much more effective.
Sometimes, lower-level commands are more efficient. I still use `reg.exe` for certain automation scripts because it's faster. You might find that mixing tools can yield better performance.
It's likely that the delay is related to timeouts in WMI. The `Get-SmbMapping` command does a lot of processing which can increase the time taken. On the other hand, `net use` seems to have simpler and more direct logic. You might be onto something with those timeout settings.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically