Sure. I would definitely go with a pure Powershell solution. I’ve found that when you start to try and mix bat or python or anything like that into a powershell script the interpreter can sometimes not handle the returned output very well.
Powershell is object-oriented. If you use strictly Powershell cmdlets to remove your network drives, and map your new ones, you are going to be working with Powershell objects, which is exactly what it wants to do in the first place. Does the network drive have the same drive letter across everything you need to change it on, or is it mixed up? If it is mixed up, it might be easier to go after the root. Check this out:
Get-PSDrive | Where-Object { $_.DisplayRoot -eq "\\dc1\finance" } | Remove-PSDrive
Get-PSDrive | Where-Object { $_.DisplayRoot -eq "\\dc1\production" } | Remove-PSDrive
You’ll notice I used DisplayRoot instead of Root.
If you do this:
Get-PSDrive | Get-Member
You will notice a DisplayRoot and a Root property, but on the output of just Get-PSDrive the path the network shares have is just displayed as root. Looks like they are using a named property to change the name of that column in the output. Makes things a little confusing. If you target DisplayRoot though, you’ll get the values you are after.
You can then create your new network drives using this bit of code:
New-PSDrive -Name "P" -Root "\\dc2\production" -Persist -PSProvider "FileSystem"
New-PSDrive -Name "F" -Root "\\dc2\finance" -Persist -PSProvider "FileSystem"
Take note of this however with regard to using New-PSDrive. Copy/Pasted from the MSDN docs here: https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/new-psdrive
The following features are added to New-PSDrive in Windows PowerShell 3.0:
Mapped network drives. You can use the Persist parameter of New-PSDrive to create Windows mapped network drives. Unlike temporary Windows PowerShell drives, Windows mapped network drives are not session-specific. They are saved in Windows and they can be managed by using standard Windows tools, such as File Explorer and Net Use. Mapped network drives must have a drive-letter name and be connected to a remote file system location. When your command is scoped locally (no dot-sourcing), the Persist parameter does not persist the creation of a PSDrive beyond the scope in which the command is running. If you are running New-PSDrive inside a script, and you want the drive to persist indefinitely, you must dot-source the script. For best results, to force a new drive to persist indefinitely, add the Scope parameter to your command, and set its value to Global.