param( $ComputerName = 'somehostname.full.qualified.domain', [switch] $GetCredential=$false, [switch] $ForceGetCredential=$false, [System.Management.Automation.PSCredential] $Credential=$null, [switch] $ClientTrust=$false ) if ($ClientTrust){ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" `"$args`"" -Verb RunAs; exit } Enable-PSRemoting -Force Set-Item WSMan:localhost\client\trustedhosts -value * Get-Item WSMan:localhost\client\trustedhosts exit } $SessionArgs = @{ ComputerName = $ComputerName SessionOption = New-CimSessionOption -Protocol Dcom } if ($null -ne $Credential){ $SessionArgs.Credential = $Credential } if ($ForceGetCredential -or $GetCredential){ if ($ForceGetCredential -or ($null -eq $global:psremoteremotecred)) { $global:psremoteremotecred = Get-Credential } $SessionArgs.Credential = $global:psremoteremotecred } $SessionArgs | Out-Host $cmd_reg = "New-Itemproperty -name LocalAccountTokenFilterPolicy -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -propertyType DWord -value 1" $cmd_enable = "Enable-PSRemoting -Force" $Session = New-CimSession @SessionArgs if ($null -ne $Session){ $MethodArgs = @{ ClassName = 'Win32_Process' MethodName = 'Create' CimSession = $Session Arguments = @{ CommandLine = "powershell Start-Process powershell -ArgumentList '$cmd_reg;$cmd_enable;get-netconnectionprofile'" } } Invoke-CimMethod @MethodArgs }