1
2
3
4
5
6
7
8
9
| $jsonPath = Join-Path -Path $PSScriptRoot -ChildPath 'settings.json'
$config = Get-Content -Path $jsonPath -Raw | ConvertFrom-Json
$securePassword = ConvertTo-SecureString -String $config.Password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($config.Username, $securePassword)
$session = New-PSSession -ComputerName "TargetComputer" -Credential $credential
Invoke-Command -Session $session -ScriptBlock { hostname }
Remove-PSSession -Session $session
|