修改Linux hostname

$keyFile = "D:\vm\linux.key"
$key = New-Object Byte[] 32
$key | out-file $keyFile

Read-Host "Enter Password" -AsSecureString | ConvertFrom-SecureString -key $key | Out-File "D:\vm\linux.txt"

$userName = "root"
$passwdFile = "D:\vm\linux.txt"
$keyFile = "D:\vm\linux.key"
$key = Get-Content $keyFile
$Cred = New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $userName, (Get-Content $passwdFile | ConvertTo-SecureString -Key $key)

$vms = Get-Content D:\VM\vm2.txt

echo $vms

foreach ($vm in $vms)

{

$st = "hostnamectl set-hostname $vm"

Invoke-VMScript -VM $vm -ScriptType Bash -ScriptText $st -GuestCredential $Cred

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章