简体   繁体   English

Powershell / Batch网络映射驱动器

[英]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.

相关问题 如何使用Powershell删除映射的网络驱动器? - How to remove mapped network drive with Powershell? 相当于批处理命令“ START”的Powershell使用映射的驱动器打开窗口 - Powershell equivalent of Batch command “START” to open window with Mapped Drive PowerShell 脚本将文件从映射的网络驱动器复制到相同映射的网络驱动器的子文件夹,然后将日期添加到文件名 - PowerShell script to copy a file from a Mapped Network Drive to a Subfolder of the same mapped, network drive then add the date to the file name 从批处理文件运行Powershell命令以重命名网络驱动器 - Run Powershell Command from Batch File to Rename Network Drive 识别未使用的网络映射驱动器 - Identify unused network mapped drive Powershell检测到额外的映射驱动器 - Powershell detecting an extra mapped drive powershell 在 gpo 上创建映射驱动器 - powershell to create mapped drive on gpo 退出 powershell 脚本后,通过 New-PSDrive 映射的网络驱动器消失 - Mapped network drive via New-PSDrive disappears after exiting powershell script Powershell通过映射的网络驱动器删除sharepoint在线库中的所有文件扩展名 - Powershell to remove all file extensions in sharepoint online library through mapped network drive 无法使用 powershell 从映射的网络驱动器复制项目,因为文件包含奇怪的字符 - Unable to copy item from mapped network drive using powershell as file contains wierd characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM