Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

function powershell to know at time what letter is free to mount smb connexion

Publié le par damcuvelier

function powershell to know at time what letter is free to mount smb connexion:

function getfreedrive{
$PSDriveNames = (Get-PSDrive -PSProvider filesystem).Name
$mappeds = (Get-ChildItem -Path HKCU:\Network\).Name.replace("HKEY_CURRENT_USER\Network\","")
foreach($mapped in $mappeds){
    $mapdrive = $mapped.replace("HKEY_CURRENT_USER\Network\","")
    if($PSDriveNames -notcontains $mapdrive){$PSDriveNames += $mapdrive}
}
$drivelist=$PSDriveNames
# $drivelist=(Get-PSDrive -PSProvider filesystem).Name
    Foreach ($drvletter in "KLMNOQRTUVW".ToCharArray()) {
        If ($drivelist -notcontains $drvletter) {
            return $drvletter
            break
        }
    }
}

Commenter cet article