Sha256: 29bde87664c58eb4b49d496aa445c3a337832e9dc77796539cacc1ea4b228a70

Contents?: true

Size: 1.9 KB

Versions: 27

Compression:

Stored size: 1.9 KB

Contents

Param(
    [string]$hostname,
    [string]$port,
    [string]$username,
    [string]$password
)
# If we are in this script, we know basic winrm is working
# If the user is not using a domain acount and chances are
# they are not, PS Remoting will not work if the guest is not
# listed in the trusted hosts.

$encrypted_password = ConvertTo-SecureString $password -asplaintext -force
$creds = New-Object System.Management.Automation.PSCredential (
    "$hostname\\$username", $encrypted_password)

$result = @{
    Success = $false
    PreviousTrustedHosts = $null
}
try {
    invoke-command -computername $hostname `
                   -Credential $creds `
                   -Port $port `
                   -ScriptBlock {} `
                   -ErrorAction Stop
    $result.Success = $true
} catch{}

if(!$result.Success) { 
    $newHosts = @()
    $result.PreviousTrustedHosts=(
        Get-Item "wsman:\localhost\client\trustedhosts").Value
    $hostArray=$result.PreviousTrustedHosts.Split(",").Trim()
    if($hostArray -contains "*") {
        $result.PreviousTrustedHosts = $null
    }
    elseif(!($hostArray -contains $hostname)) {
        $strNewHosts = $hostname
        if($result.PreviousTrustedHosts.Length -gt 0){
            $strNewHosts = $result.PreviousTrustedHosts + "," + $strNewHosts
        }
        Set-Item -Path "wsman:\localhost\client\trustedhosts" `
          -Value $strNewHosts -Force

        try {
            invoke-command -computername $hostname `
                           -Credential $creds `
                           -Port $port `
                           -ScriptBlock {} `
                           -ErrorAction Stop
            $result.Success = $true
        } catch{
            Set-Item -Path "wsman:\localhost\client\trustedhosts" `
              -Value $result.PreviousTrustedHosts -Force
            $result.PreviousTrustedHosts = $null
        }
    }
}

Write-Output $(ConvertTo-Json $result)

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
vagrant-unbundled-2.0.3.0 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-2.0.2.0 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-2.0.1.0 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-2.0.0.1 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-1.9.8.1 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-1.9.7.1 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-1.9.5.1 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-unbundled-1.9.1.1 plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/commands/powershell/scripts/enable_psremoting.ps1
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/commands/powershell/scripts/enable_psremoting.ps1