3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ローカルPCにログイン中ユーザーの、Microsoftアカウントの CID を取得するPowerShellスクリプト

Posted at
$item = Get-Item "HKCU:\Software\Microsoft\IdentityCRL\UserExtendedProperties"
$item.GetSubKeyNames() | select @{ name = "MS Account"; Expression = {$_} }, @{ name = "CID"; Expression = { $item.OpenSubKey($_).GetValue("cid") } }

上記で取得したCIDを使い、以下のパスを指定することでExplorerからOneDriveにアクセス可能。(WebDAV接続)
https://d.docs.live.net/{CID}

普通にOneDriveクライアントで接続すると同期してしまうのが、この方法だと同期しないクラウドストレージとして使える。

ついでに、ネットワークドライブに接続するスクリプト

$cid         = "{MicrosoftアカウントのCID}"
$DriveLetter = "X"
$net = New-Object -ComObject WScript.Network
$net.MapNetworkDrive("{0}:" -f $DriveLetter, "\\d.docs.live.net@SSL\$cid", $false)

マップされたドライブのラベルが既定でCIDになってしまうので、それも見栄えのよいラベルに変えたい。

以下未検証>
$shell = New-Object -ComObject Shell.Application
$shell.NameSpace( "{0}:\" -f $DriveLetter ).Self.Name = "尾根ドライブ"
とか
$drive = Get-WmiObject -Class win32_volume -Filter ("DriveLetter = '{0}:'" -f $DriveLetter)
Set-WmiInstance -input $drive -Arguments @{ Label = "尾根ドライブ"}
とか

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?