通过Powershell映射Onedrive for Business

时间:2017-02-24 06:02:19

标签: powershell windows-10 onedrive

我最近遇到了这个问题,可以从URL创建Onedrive for Business作为desktop.lnk:

$user = [Environment]::UserName
$domain = "contoso.com"; # your Federated domain
$urldomain = "_contoso_com"
$mappath = "\\contoso-my.sharepoint.com@SSL\DavWWWRoot\personal\" + $user + $urldomain + "\Documents"
$iepath = "c:\Program Files\Internet Explorer\iexplore.exe"
$sharepoint = "https://contoso-my.sharepoint.com"

#$ie.visible = $true #Uncomment this for debugging
Start-Process -FilePath $iepath -ArgumentList $sharepoint -WindowStyle Minimized
sleep -seconds 12 # give plenty of time to redirect
NET USE P: $mappath /PERSISTENT:YES
sleep -seconds 5
$targetpath = Get-Item("\\contoso-my.sharepoint.com@SSL\DavWWWRoot\personal\" + $user + $urldomain + "\Documents")
$Wshshell = New-Object -ComObject wscript.shell
$shortcut = $Wshshell.CreateShortcut("$home\Desktop\Onedrive.lnk")
$shortcut.TargetPath = $targetpath.FullName
$shortcut.Save()
#Stop-Process -Name iexplore

在这种情况下,它会创建.lnk,但.lnk无法将我引导到此网络驱动器。换句话说,当我在域网络上映射它们时,.lnk就会被破坏。 (对于所有Windows 8和Windows 10计算机来说都是一样的)

但是,我无法弄清楚如何让不在域中的用户仍然运行此脚本并且能够从他们的个人笔记本电脑映射他们的Onedrive而不通过“我的电脑”和“映射为网络驱动器”全部那些东西。

感谢您的帮助

0 个答案:

没有答案