Getting a free drive letter

后端 未结 11 585
青春惊慌失措
青春惊慌失措 2020-12-10 13:40

I saw the Get-NextFreeDrive function in this answer and I wondered if there was a more efficient way to do this. It appears that the function in the linked answ

11条回答
  •  不知归路
    2020-12-10 14:00

    just going to add one that works for remote drive letters $computer will be the input and $driveletter would contain the next available drive on the remote computer

    67..90 | foreach {if(((GWmi win32_logicaldisk -computer $computer -Property DeviceID).deviceID).Substring(0,1) -notcontains [char]$_){$driveLetter = [char]$_; break}}
    

    might be able to shorten that but at that length its clear to see whats going on

提交回复
热议问题