CDSoftware/OneDrive.ps1
function Get-OneDriveSettingFileName { <# .SYNOPSIS ��ȡ�����ϰ�װ��ij�� OneDrive �ļ��е������ļ�·���� .DESCRIPTION ��ȡ�����ϰ�װ��ij�� OneDrive �ļ��е������ļ�·���� .PARAMETER Numer OneDrive �ļ��е���š�0 ��ʾ�����ļ��У������� k ��ʾ�� k �� Business �ļ��С�ȱʡ��ʾ 0�� .EXAMPLE Get-OneDriveSettingFileName .EXAMPLE Get-OneDriveSettingFileName 1 .OUTPUTS ��ȡ�������ļ���·�� String����������������ļ����� $null�� #> [CmdletBinding()] PARAM( [parameter(ValueFromPipeline=$true)] [Int32] $Number = 0 ) PROCESS { if ($Number -lt 0) { throw "����ֵ $Number �Ƿ�������Ϊ��Ȼ����" } elseif ($Number -eq 0) { $folder = "$env:LOCALAPPDATA\Microsoft\OneDrive\settings\Personal" if (Test-Path $folder -PathType Container) { $ini = Get-ChildItem -Path $folder | Where-Object {$_.Name -like '????????????????.ini'} if ($null -eq $ini) { return $null } elseif ($ini -is [System.Array]) { throw "�����˶�������������ļ���$ini" } else { return $ini.FullName } } else { return $null } } $folder = "$env:LOCALAPPDATA\Microsoft\OneDrive\settings\Business$Number" if (-not (Test-Path $folder -PathType Container)) { return $null } $ini = Get-ChildItem -Path $folder $ini = $ini | Where-Object {$_.Name -like '????????-????-????-????-????????????.ini'} if ($null -eq $ini) { return $null } elseif ($ini -is [System.Array]) { throw "�����˶�������������ļ���$ini" } else { return $ini.FullName } } } function Get-OneDrivePath { <# .SYNOPSIS ��ȡ�����ϰ�װ��ij�� OneDrive �ļ��е�λ�á� .DESCRIPTION ��ȡ�����ϰ�װ��ij�� OneDrive �ļ��е�λ�á���ȡ������ %LOCALAPPDATA%\Microsoft\OneDrive �ļ����е���Ϣ�� .PARAMETER Numer OneDrive �ļ��е���š�0 ��ʾ�����ļ��У������� k ��ʾ�� k �� Business �ļ��С�ȱʡ��ʾ 0�� .EXAMPLE Get-OneDrivePath .EXAMPLE Get-OneDrivePath 1 .OUTPUTS ��ȡ�����ļ���·�� String����������������ļ��У��� $null�� #> [CmdletBinding()] PARAM( [parameter(ValueFromPipeline=$true)] [Int32] $Number = 0 ) PROCESS { if ($Number -eq 0) { return "$HOME\OneDrive" } $fn = Get-OneDriveSettingFileName $Number if ($null -eq $fn) { return $null } $line = Get-Content $fn -Encoding Unicode | Select-Object -First 1 $i = 0 while ($true) { if (-not ($line -match '^"([^"]+?)"\s+(.*)')) { if (-not ($line -match '^(\S+?)\s+(.*)')) { throw "�������⣬��������λ�á�" } } $i += 1 $p1 = $Matches[1] $p2 = $Matches[2] if ($i -eq 15) { return $p1 } else { $line = $p2 } } } } function Set-OneDrivePath { <# .SYNOPSIS ���ñ�����ij�� OneDrive Business �ļ��е�λ�á� .DESCRIPTION ���ñ�����ij�� OneDrive Business �ļ��е�λ�á�������˵�����õ��� %LOCALAPPDATA%\Microsoft\OneDrive �ļ����е���Ϣ�� .PARAMETER Numer OneDrive �ļ��е���ţ�Ϊ��������k ��ʾ�� k �� Business �ļ��С� .PARAMETER Path ��λ�á� .EXAMPLE Set-OneDrivePath 1 E:\OneDriveB .OUTPUTS void #> [CmdletBinding()] PARAM( [parameter(Mandatory=$true)] [Int32] $Number, [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [String] $Path ) PROCESS { if ($Number -le 0) { throw "Number ֵ $Number �Ƿ�������Ϊ��������" } $fn = Get-OneDriveSettingFileName $Number if ($null -eq $fn) { throw "Number ֵ $Number �������ڵ� $Number �� OneDrive �ļ��С�" } $oldPath = Get-OneDrivePath $Number $content = Get-Content $fn -Raw -Encoding Unicode $content.Replace($oldPath, $Path) | Out-File $fn -Encoding Unicode Write-Verbose "�ѽ��� $Number �� OneDrive �ļ��е�λ���� $oldPath ��Ϊ $Path��" } } |