使用powershell添加网络位置

注意修改变量

# 定义网络共享的路径和要创建的网络位置名称
$networkSharePath = "\\10.106.7.22\X000"
$networkLocationName = "NAS"

# 创建网络位置文件夹路径
$networkLocationsPath = "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Network Shortcuts"
$newNetworkLocationPath = Join-Path -Path $networkLocationsPath -ChildPath "$networkLocationName.lnk"

# 创建一个 WScript.Shell 对象来创建快捷方式
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($newNetworkLocationPath)

# 设置快捷方式的目标路径
$shortcut.TargetPath = $networkSharePath

# 保存快捷方式
$shortcut.Save()

# 输出完成信息
Write-Host "网络位置 $networkLocationName 已成功添加。"

评论