Why is "net use" so much quicker than "Get-SmbMapping"?
Asked by
TechExplorer37
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
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.
Reply to this answer
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.
Reply to this answer
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!
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions