1

PowerShellスクリプトで次のコマンドを実行して、コンピューターの名前を変更します。スクリプトはコンピューターのスタートアップスクリプトGPOによって実行されるため、コマンド内で資格情報を渡す必要があります。起動時にスクリプトを実行するとスクリプトに何が起こっているのかわからないので、通常のユーザーとしてログオンしているときにスクリプトを実行してテストしています。

(Get-WmiObject win32_computersystem).Rename( $NewName,'Password','domain\username')

このコマンドは、「5」のReturnValueを返します-アクセスが拒否されました。ユーザー名とパスワードを渡すにはどうすればよいですか?(スクリプト内のパスワードに関するセキュリティリスクを理解しています)

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     : 
__DYNASTY        : __PARAMETERS
__RELPATH        : 
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         : 
__NAMESPACE      : 
__PATH           : 
ReturnValue      : 5
PSComputerName   : 
4

2 に答える 2

6

これを常に同じマシンで実行している場合、または関連付けられているアカウントがローミングしている場合、IIRC は DPAPI に依存して次のようにキーを保存できます。

# Capture once and store to file
$passwd = Read-Host "Enter password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd
$encpwd
$encpwd > $path\password.bin

# Later pull this in and restore to a secure string
$encpwd = Get-Content $path\password.bin
$passwd = ConvertTo-SecureString $encpwd

# Extract a plain text password from secure string
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($passwd)
$str =  [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$str

それがうまくいかない場合は、このアプローチを使用できますが、上記のアプローチほど安全ではありません。

$key = 1..32 | ForEach-Object { Get-Random -Maximum 256 }
$passwd = Read-Host "Enter password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd -Key $key
$encpwd

# Could easily modify this to store username also
$record = new-object psobject -Property @{Key = $key; EncryptedPassword = $encpwd}
$record
$record | Export-Clixml $path\portablePassword.bin

# Later pull this in and restore to a secure string
$record = Import-Clixml $path\portablePassword.bin
$passwd = ConvertTo-SecureString $record.EncryptedPassword -Key $record.Key

# Extract a plain text password from secure string
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($passwd)
$str =  [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$str
于 2012-12-12T16:24:37.273 に答える
0

ここで次のものが見つかりました:

$credential = Get-Credential
Get-WmiObject Win32_ComputerSystem -ComputerName OLDNAME -Authentication 6 |
ForEach-Object {$_.Rename("NEWNAME",$credential.GetNetworkCredential().Password,$credential.Username)}

クレデンシャルを渡すことができるように認証レベルを設定する必要があるようです(オプションでGet-Credential CMDLetを使用)。現時点では、これをテストするためのボックスがありません。

于 2012-12-12T15:29:49.890 に答える