[英]Powershell/Batch network mapped drive
I want a powershell/batch script that map a drive on a free letter. 我想要一个powershell / batch脚本,用于在免费信件上映射驱动器。 Or test letters then map on a free one.
或者测试信件然后在免费的地图上映射。
I'm sure there is something easier than this. 我确信有比这更容易的事情。
$tab = @()
$tab = @('A:', 'B:', 'C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:', 'K:', 'L:', 'M:', 'N:', 'O,:', 'P:', 'Q:', 'R:', 'S:', 'T:', 'U:', 'V:', 'W' ,'X:', 'Y:', 'Z')
for($i = 0;$i -lt 26;$i++){
if(net use $tab[$i] > $null){
Write-Host $tab[$i] "`tExists"
}
else{
Write-Host $tab[$i] "`tDoesn't exist"
}
}
I need my PS script to write something in a .bat script. 我需要我的PS脚本在.bat脚本中写一些东西。 So, 1) in my PS script find free letters then write it to the .bat script like this
所以,1)在我的PS脚本中找到免费信件,然后将其写入.bat脚本,就像这样
$freeletter | Output-File -Append ....
or 2) my .bat script does something like that : 或者2)我的.bat脚本做了类似的事情:
Is G: free ?
No Is H: free ?
Yes : Map It -> $mapdrive_1 = "H:"
Is I: free ?
No Is J: Free ?
Yes : Map it -> $mapdrive_2 = "J:"
#Once it's done I got my ONLY 2 mapped drives
$mapdrive_1
$mapdrive_2
#then i can do
net use $mapdrive_1 "my\path1"
net use $mapdrive_2 "my\path1"
start robocopy $mapdrive_1 $mapdrive_2 /options
net use $mapdrive_1 /DELETE
net use $mapdrive_2 /DELETE
net use $mapdrive_1 "my\path2"
net use $mapdrive_2 "my\path2"
start robocopy $mapdrive_1 $mapdrive_2 /options
net use $mapdrive_1 /DELETE
net use $mapdrive_2 /DELETE
Hope you understand what I mean :) 希望你明白我的意思:)
Regards, 问候,
Nico. 尼科。
这将输出所有免费字母,然后您可以通过管道选择对象来获取第一个:
ls function:[a-z]: -name | where {-not (get-psdrive $_[0] -ea 0)}
$Mapdrive = "\\DRIVE NAME\My\Path\"
使用我使用的驱动器别名会使驱动器号无关紧要,如果由于某种原因驱动器号更改,这将特别方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.