$PSExec=".\SetupWindows\psexec.exe"
$VMName="test10pl4win2"
$VMIpIs="192.168.191.212"
$VMIpv4="192.168.191.212"
$VMNetw="24"
$VMGwIP="192.168.191.1"
$VMDns1="9.9.9.9"
$VMDns2="8.8.8.8"
$VMUser="$VMIpIs\administrator"
$VMPass="Tarantu95"
$VMPasw=ConvertTo-SecureString $VMPass -AsPlainText -Force
$VMCred=New-Object Management.Automation.PSCredential ($VMUser,$VMPasw)
cls
function VMLogon    {Invoke-Command -Credential $VMCred -ComputerName $VMIpIs {echo hello}}
function VMReboot   {Invoke-Command -Credential $VMCred -ComputerName $VMIpIs {Restart-Computer}}
function VMShutdown {Invoke-Command -Credential $VMCred -ComputerName $VMIpIs {Stop-Computer}}
function VMConfig   {Invoke-Command -Credential $VMCred -ComputerName $VMIpIs -ArgumentList $VMIpv4,$VMGwIP,$VMNetw,$VMDns1,$VMDns2,$VMname -ScriptBlock {
  $adapter=Get-NetAdapter | ? {$_.Status -eq "up"};$IPType="IPv4";If (($adapter|Get-NetIPConfiguration).IPv4Address.IPAddress){$adapter|Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false};If (($adapter|Get-NetIPConfiguration).Ipv4DefaultGateway){$adapter|Remove-NetRoute -AddressFamily $IPType -Confirm:$false}
  $adapter|New-NetIPAddress -AddressFamily $IPType -IPAddress $args[0] -PrefixLength $args[2] -DefaultGateway $args[1]
  $adapter|Set-DnsClientServerAddress -ServerAddresses ($args[3],$args[4])
  Rename-Computer -NewName $args[5] -Restart -Force
 }
}
#Start-Job -ScriptBlock {}
#https://powershell.org/forums/topic/using-invoke-command-with-a-timeout/
#Read-Host "Press ENTER to continue or CTRL+C to quit"
