Remote Output not showing

This topic contains 4 replies, has 2 voices, and was last updated by  Tim Mullen 2 weeks, 2 days ago.

  • Author
  • #103670

    Tim Mullen

    Hi all,
    I'm a bit of a dabbler/bodger in powershell and by no means any sort of professional. I have the following script which is to take an entered remote computer name, check the graphics card driver version, output the results and and then give the menu choice. I think the script isn't pausing for long enough to output the details from the remote computer. Is there a way to get it to pause to output the details or is there a better way?

    [String]$SiteName = read-host "PC Name"

    Write-host $SiteName (Test-Connection -count 1 $SiteName -quiet)
    $strQuit = Read-Host "Do you want to test again? (Y/N)"
    Until ($strQuit -eq "N")

    Get-WmiObject Win32_VideoController -ComputerName $SiteName | select SystemName, Description, DriverVersion

    Write-Host "1: Clone"
    Write-Host "2: Extend"
    $input = Read-Host "Please make a selection"
    switch ($input)
    '1' {
    Invoke-Command -ComputerName $SiteName -ScriptBlock {C:\Windows\System32\DisplaySwitch.exe /clone}
    } '2' {
    Invoke-Command -ComputerName $SiteName -ScriptBlock {C:\Windows\System32\DisplaySwitch.exe /extend}
    }until ($input -eq 'q')

  • #103678

    Don Jones

    Well, Get-WmiObject is synchronous, meaning that the script won't continue until Get-WmiObject is done. So that ain't it. Have you tried just ending your script after Get-WmiObject, and seeing if it ever outputs anything? Normally when Get-WmiObject doesn't produce anything, it's because there's nothing to produce, which often means an erroneous query.

  • #103705

    Tim Mullen

    I've removed everything past the Get-WMIObject line, run it and it returns the video card detail perfectly from the remote computer. I add the bottom half back in again, run it and it doesn't produce the details from the video card when I call the line.

  • #103708

    Don Jones

    Yeah, so, you're playing a bit fast-and-loose with the pipeline and that may be the trouble. PowerShell commands don't just emit text to the console (like Write-Host does); they produce objects, which then run through a formatting system. When the formatting system gets multiple things handed to it, it can get a bit confused.

    For example, after your Get-WmiObject/Select-Object, pipe to Out-GridView. I'm guessing you'll get a pop-up, indicating the command is indeed running, but that the console formatting system is getting weirded out about what to display. It's likely waiting for the script to end so it can figure out what to try and do.

    Coding in PowerShell is a bit different than writing a top-down script like a batch file, because PowerShell's doing a good bit under the hood and is very object- and pipeline-based. In your case, it might be easier to...

    Write-Host "$(Get-WmiObject Win32_VideoController -ComputerName $SiteName | select SystemName, Description, DriverVersion | Out-String)"

    Your script is intended for human eyeball-and-finger interaction, so you probably don't need to be mucking with the main success pipeline. Just display everything in the host application.

  • #103717

    Tim Mullen

    That code line worked like a charm Mr Jones. Thanks very much. As I say I'm not a professional but enjoy dabbling.

You must be logged in to reply to this topic.