Works on top of WinRM. Some commands have the -computername so you don't need to setup a session. For example get-wmiobject
$remoteserver = "192.168.1.152"
get-wmiobject -ComputerName $remoteserver -Credential (get-credential -Message wmi -UserName administrator) -Class Win32_NetworkAdapterConfiguration
If you are not in the same domain, you will need to thrust the target host
get-item -path WSMan:\localhost\Client\TrustedHosts
#for all Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value '*'
set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value '10.0.0.*,192.168.1.*'
Enter a session
Enter-PSSession -ComputerName $remoteserver -Credential (get-credential -UserName "administrator" -Message "PS Remote")
Get-NetIPAddress | ? { $_.IpAddress -match "^192" } | select ipaddress
exit # to disconnect
Execute a single command remotely
$ip = Invoke-Command -ComputerName $remoteserver -Credential (get-credential -UserName "administrator" -Message "PS Remote") -ScriptBlock {
Get-NetIPAddress | ? { $_.IpAddress -match "^192" } | select ipaddress
}
$ip
Make a session to reuse
$sess = new-pssession -ComputerName $remoteserver -Credential (get-credential -UserName "administrator" -Message "PS Remote")
$ip = Invoke-Command $sess -ScriptBlock { Get-NetIPAddress | ? { $_.IpAddress -match "^192" } | select ipaddress }
$ip
Passing a parameter
Invoke-Command $sess -ScriptBlock { param($regexm) Get-NetIPAddress | ? { $_.IpAddress -match $regexm } | select ipaddress } -ArgumentList "^192."
Get-PSSession | Disconnect-pssession | Remove-PSSession