Thursday, April 16, 2015

PowerShell: Box.com Drive Mapping via DAV

Thanks to a couple of web articles I found (1,2), I'm now able to connect to my Box.com account as a drive letter.

tl;dr:
net use b: \\dav.box.com@SSL\dav /u:boxuser boxpassword

Whole script:
$password = "your embedded & encrypted Box password"

$pscred = New-Object PSCredential -ArgumentList "yourboxaccount@mail.com", ($password | ConvertTo-SecureString)

#Checking if a DAV connection exists and if not, then creating one and assigning it Drive B:

if (get-psdrive|? {$_.currentlocation -like "Your Box Root Folder\Some Box Subfolder*"}){$drive = get-psdrive|? {$_.currentlocation -like "Your Box Root Folder\Some Box Subfolder*"}|select -expandproperty root}else{net use b: \\dav.box.com@SSL\dav /u:yourboxaccount@mail.com $pscred.getnetworkcredential().Password;$drive = "B:\"}

Now you can use Robocopy instead of "Box Sync" to sync your Box.com data:
robocopy "\\server\share\content" ($drive + "Your Box Root Folder\Some Box Subfolder") /s /e /v
robocopy ($drive + "Your Box Root Folder\Some Box Subfolder") "\\server\share\content" /s /e /v

No comments: