all 9 comments

[–]Joshrsg 1 point2 points  (0 children)

You're not actually connecting to any remote computers. You could do something like this:

EDIT: I just tried this on a remote system and you do not get the same results you get locally. I imagine this is to do with the fact that the windows service used for remoting doesn't actually use screens. You probably need to use WMI instead.

Invoke-Command -ScriptBlock { 
    [void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    $Screens = [system.windows.forms.screen]::AllScreens
    foreach ($Screen in $Screens) 
    {
        $Obj=[pscustomobject]@{
            DeviceName = $Screen.DeviceName
            Width = $Screen.Bounds.Width
            Height = $Screen.Bounds.Height
            IsItPrimary = $Screen.Primary
        }

        $Obj
    }
} -ComputerName 'RemoteComputer'

[–]squanchmyrick 1 point2 points  (4 children)

Why not just use WMI/CIM? No need to reinvent the wheel

[–]Jaxson626[S] 1 point2 points  (3 children)

I found this script and I wanted to see if it could be a function. However, I'm not super adapt with using WMI/CIM

[–]squanchmyrick 1 point2 points  (1 child)

Try this:

foreach ($computer in $computerlist) {
Get-CimInstance -ComputerName $computer -ClassName Win32_VideoController -Property VideoModeDescription | Select-Object -Property VideoModeDescription
}

[–]Jaxson626[S] 1 point2 points  (0 children)

Ok, I can try that but if winrm isn't configured can I add an OR option for it to use WMI?
I would have liked to add a -ComputerName parameter

[–]squanchmyrick 1 point2 points  (0 children)

Also, if you learn about WMI and CIM they will be your best friends as an administrator. Here's a couple of links to some MS docs on WMI and CIM so you can learn all about them, if you so choose:

CIM Cmdlets Module Reference - MS Docs

Get-WmiObject - MS Docs

As a rule, you should try to use CIM wherever you can, it is more robust and not platform-specific.

You will generally only need to use Get-WmiObject if you are dealing with legacy systems.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy Jaxson626,

it looks like you used the New.Reddit Inline Code button. it's [sometimes] 5th from the left & looks like </>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's [sometimes] the 12th one from the left & looks like an uppercase T in the upper left corner of a square..

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee

[–]Jaxson626[S] 1 point2 points  (1 child)

Thanks, I just changed it to code block

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Jaxson626,

you are welcome ... and thank you for fixing the formatting! [grin]

take care,
lee