File size: 537 Bytes
4176b74 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
param(
[string] $Name,
[string] $Username,
[securestring] $Password = (New-Object System.Security.SecureString),
[string] $CMD
)
$cred = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList($Username, $Password)
if ($null -eq $CMD) {
Enter-PSSession `
-VMName $Name `
-Credential $cred `
-Authentication NegotiateWithImplicitCredentials
} else {
Invoke-Command `
-VMName $Name `
-ScriptBlock { $cmd } `
-Credential $cred
} |