With this code snippet a share can be mapped to the next free drive letter.
1 2 3 4 5 6 |
$share = "\\any\unc\path" $PSProviderAlphabet = [char[]]([char]'C'..[char]'Z') $UsedPSProvider = (get-psdrive).Name | Sort-Object $FreePSProvider = $PSProviderAlphabet | ? {$UsedPSProvider -notcontains $_} New-PSDrive -Name $FreePSProvider[0] -PSProvider "FileSystem" -Root $share |
It is especially useful if you have to work with a driveletter in the code or if the share has to be mapped in the Scirpt and has to be removed at the end of the script.
0