第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用PowerShell憑據(jù)而不提示輸入密碼

使用PowerShell憑據(jù)而不提示輸入密碼

使用PowerShell憑據(jù)而不提示輸入密碼我想重新啟動屬于域的遠程計算機。我有一個管理員帳戶,但我不知道如何從powershell使用它。我知道有一個Restart-Computercmdlet,我可以通過憑證但是如果我的域名是,例如mydomain,我的用戶名是myuser,我的密碼是mypassword使用它的正確語法?我需要安排重啟,所以我不必輸入密碼。
查看完整描述

3 回答

?
哈士奇WWW

TA貢獻1799條經(jīng)驗 獲得超6個贊

還有另一種方式,但......

如果你 不想在腳本文件中輸入密碼,請不要這樣做(在腳本中存儲密碼不是一個好主意,但我們中的一些人只是想知道如何。)

好的,這是警告,這是代碼:

$username = "John Doe"$password = "ABCDEF"$secstr = New-Object -TypeName System.Security.SecureString$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr

$cred 將獲得John Doe的憑證,密碼為“ABCDEF”。

替代方法是準備好使用密碼:

$password = convertto-securestring -String "notverysecretpassword" -AsPlainText -Force


查看完整回答
反對 回復(fù) 2019-07-25
?
幕布斯7119047

TA貢獻1794條經(jīng)驗 獲得超8個贊

關(guān)于存儲憑證,我使用兩個函數(shù)(通常在從我的配置文件加載的模塊中):


#=====================================================================

# Get-MyCredential

#=====================================================================

function Get-MyCredential

{

param(

$CredPath,

[switch]$Help

)

$HelpText = @"


    Get-MyCredential

    Usage:

    Get-MyCredential -CredPath `$CredPath


    If a credential is stored in $CredPath, it will be used.

    If no credential is found, Export-Credential will start and offer to

    Store a credential at the location specified.


"@

    if($Help -or (!($CredPath))){write-host $Helptext; Break}

    if (!(Test-Path -Path $CredPath -PathType Leaf)) {

        Export-Credential (Get-Credential) $CredPath

    }

    $cred = Import-Clixml $CredPath

    $cred.Password = $cred.Password | ConvertTo-SecureString

    $Credential = New-Object System.Management.Automation.PsCredential($cred.UserName, $cred.Password)

    Return $Credential

}

還有這個:


#=====================================================================

# Export-Credential

# Usage: Export-Credential $CredentialObject $FileToSaveTo

#=====================================================================

function Export-Credential($cred, $path) {

      $cred = $cred | Select-Object *

      $cred.password = $cred.Password | ConvertFrom-SecureString

      $cred | Export-Clixml $path

}

你這樣使用它:


$Credentials = Get-MyCredential (join-path ($PsScriptRoot) Syncred.xml)

如果憑證文件不存在,則第一次會提示您,此時它會將憑證存儲在XML文件中的加密字符串中。第二次運行該行時,xmlfile就會出現(xiàn)并自動打開。


查看完整回答
反對 回復(fù) 2019-07-25
  • 3 回答
  • 0 關(guān)注
  • 1472 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號