Battle Faction Puzzle 6

This topic contains 4 replies, has 2 voices, and was last updated by  Yubu 2 months, 3 weeks ago.

  • Author
  • #93987

    Axel Bøg Andersen

    A possible solution could be this:

    It works on Windows and Linux. It takes piped hostnames.

  • #93988

    Axel Bøg Andersen

    Authentication drives me crazy. My work machine will only allow me to run Invoke-Command if I set Authentication to Basic. My private machine only wants whatever is default.

    winrm settings are alike on the two machines and firewall settings are correct. Luckily Linux doesn't care and runs the code smoothly.

    Under all circumstances ComputerName and Credential goes hand in hand. I added a Authentication parameter and changed the rule for adding ComputerName to the parameters for the Invoke-Command cmdlet.

    It seems to be a bit more tricky to get the uptime from the Linux machine remotely from the Windows box – furtunately that is not a request in the puzzle 😀

  • #94026


    6.0: [pscustomobject]@{comp="server1","server2";OS="Windows"} | myuptime
    5.1: [pscustomobject]@{comp="server1","server2";OS="Windows"} | myuptime -credential (get-credential)
    Linux: works only locally.
    (gps init).startTime will give the alternative to boottime.

    function Get-MyUptime {
    	param (
    	process {
    		($comp) | %{
    			if ($PSVersionTable.OS -match "Linux") {$OS="Linux"} else {$OS="Windows"}
    			if ($OS -match "Windows") {
    				if ($PSVersionTable.PSEdition -eq "Desktop") {
    					if (!$cmp) {$cmp="localhost"}
    					$sysinfo = gwmi Win32_OperatingSystem -comp $cmp -Credential $creds -ea SilentlyContinue
    					if ($sysinfo.LastBootUpTime) {$boottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($sysinfo.LastBootUpTime)} 
    				else {
    					if (!$cmp) {$sysinfo = gcim Win32_OperatingSystem}
    					else {$sysinfo = icm -comp $cmp -Credential $creds {gcim Win32_OperatingSystem}}
    			if ($OS -match "Linux") {
    				$boottime=get-date (uptime -s)
    			if ($OS -match "Windows") {$props.Host=$sysinfo.CSName}
    			if ($OS -match "Linux") {$props.Host=$hostname}
    			$object=New-Object -TypeName psobject -Property $props
  • #94143


    In params $comp and $OS ValueFromPipeline=$true, is missing by error.

  • #94581


    This will work from Windows to Linux remotely with Powershell 6.0 and OpenSSH installed.

    get-date (icm -HostName $cmp -SSHTransport -ScriptBlock {uptime -s} -UserName user)


You must be logged in to reply to this topic.