搜索此問題的答案可以找到很多關于 GitHub 憑據的資訊,但沒有找到有關此特定問題的資訊。我開始使用 PowerShell (PoSH) Cmdlet“Get-Credential”,因為我的公司使用雙因素身份驗證 (2FA),因此用戶名/密碼無法從我的桌面(用戶帳戶)遠程到服務器(管理員帳戶)。此外,我剛剛開始使用 VS Code。問題是,當運行一個簡單的 PoSH 代碼段時,在使用 Get-Credential 的 PoSH ISE 中,我得到一個彈出視窗,讓我選擇所需的證書,然后輸入一個 Pin。當我在 VS Code 中運行相同的代碼段時,彈出視窗永遠不會出現。有誰明白這是為什么,我能解決嗎?
這里是片段供參考。
$serverList = Get-Content "C:\temp\Servers.txt"
$cred = Get-Credential
ForEach ($Server in $serverList){
$OS = Invoke-Command -Credential $cred -ComputerName $Server -ScriptBlock {
(get-itemproperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName
}
Write-Host $Server, $OS
}
謝謝大家。
uj5u.com熱心網友回復:
這種行為是設計使然。當您使用 $PSVERSIONTABLE 檢查版本時,您會看到如下內容:
=====> PowerShell Integrated Console v2021.12.0 <=====
PS C:\Users\Foo> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion
默認情況下,這不是powershell.exe,這意味著它不是與 ISE 或控制臺一起使用的 Windows 本機和 Powershell 5.x 或更低版本。它是 VS Code 主機,使用pwsh.exe6.0 及更高版本的跨平臺版本。
您可以查看檔案:https : //docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-credential?view=powershell-7.2
你可以看到,在 6.x 及更高版本中,它始終專注于腳本和終端。壞訊息是 VS Code 也是圍繞跨平臺方法構建的。因此,即使您將終端中的組態檔更改為使用 Windows Powershell,如下所示,您也可以使用 PowerShell 5.1,但無法查看該提示:
"PowerShell Core": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
},
"Windows PowerShell (x64)": {
"path": "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
}
總之,您無法使用 VS Code 獲得該提示。除了powershell.exe在集成終端里打字粘貼代碼,基本不使用VS Code。它不會幫助你。對于這個要求,我會堅持使用 ISE。
uj5u.com熱心網友回復:
您可以從“查看”選單或使用
Ctrl '
然后您可以互動輸入憑據。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/402930.html
標籤:
下一篇:無法在vs代碼中更改字體
