當執行此腳本(未提升)時,該腳本會詢問密碼並對應 onedrive,然後它會自動啟動 powershell(提升)並再次詢問 Bitlocker 的密碼。
如果onedrive和bitlocker使用單一密碼,如何使其需要一次密碼?或者是否可以將變數(包含使用者輸入密碼)傳遞給新的提升的 powershell 以在腳本中使用來解鎖 bitlocker?
#
# (FIRST SET EXECUTION POLICY WITH ELEVATED POWERSHELL) Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
#
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated) {
'tried to elevate, did not work'
} else {
### START - CODE FOR "NON-ELEVATED POWERSHELL"
$pwd = Read-Host 'Enter PW:' -AsSecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
net use O: "https://d.docs.live.net/EXAMPLE-CID" /user:[email protected] $UnsecurePassword /p:no
### END - CODE FOR "NON-ELEVATED POWERSHELL"
# RUN "ELEVATED POWERSHELL"
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
### START - CODE FOR "ELEVATED POWERSHELL"
$pwd = Read-Host 'Enter PW:' -AsSecureString
Unlock-BitLocker -MountPoint "D:" -Password $pwd
exit
### END - CODE FOR "ELEVATED POWERSHELL"