Obtener la resolución de pantallas de un equipo remoto

Hola,
Soy nuevo en el fórum, y aunque tengo algo de experiencia en programación Shell,
Ahora me encuentro en el reto de obtener la resolución de pantalla o pantallas de un equipo remoto.
Para ello utilizo:

Add-Type -AssemblyName System.Windows.Forms 
[System.Windows.Forms.Screen]::AllScreens 


Lo cual me funciona bien en mi equipo con sus dos pantallas o monitores.
El problema surge cuando quiero hacerlo en otro equipo del dominio.
Para ello genero el siguiente Script en el PC-Remoto, y lo ejecuto:

# Generamos Script a ejecutar, 
# para obtener Resolución de Pantalla(s).
# En  \\$WNOMBRE_PC\C$\temp\Test_Resoluciones.PS1
 
Add-Type -AssemblyName System.Windows.Forms

$WRES_PANT = [System.Windows.Forms.Screen]::AllScreens
$WRES_PANT | Out-File -FilePath "c:\temp\ResolucionesPantalla.txt" `
                      -Encoding default -Force
# Fin Script.

Para ejecutarlo utilizo:

$WSCRIPT_PS1 = '\\' + $WNOMBRE_PC + '\C$\temp\Test_Resoluciones.PS1' 
$WPC_REMOTO  = '\\' + $WNOMBRE_PC 
C:\Windows\SysWOW64\psexec.exe -i -s $WPC_REMOTO PowerShell.exe `
                                     -ExecutionPolicy Bypass `
                                     -WindowStyle Hidden `
                                     -File $WSCRIPT_PS1 

Y leo los datos del fichero resultante:

$WFICH_TXT_IN  = '\\' + $WNOMBRE_PC + '\C$\temp\ResolucionesPantalla.txt' 
Get-Content -Path $WFICH_TXT_IN 

Pero los resultados no se parecen en nada a la realidad.
Por ello, ahora estoy intentando ejecutarlo con
Invoke-command + Start-Process,
elevando el entorno a administrador:

Invoke-Command -ComputerName $WNOMBRE_PC `
               -scriptBlock { Start-Process -FilePath powershell.exe `
                                   -ArgumentList $Using:WSCRIPT_PS1 `
                                   -Verb Runas `
                                   -WindowStyle Hidden } 

Pero aquí no consigo que se ejecute el script.

Alguien podría ayudarme?

Patricio,
Welcome to the forum. :wave:t3:

This is an english forum. Could you please translate your question to english?

And please do not mix code and text.

Thanks in advance.

Hello, 
I'm new to the forum, and although I have some experience in Shell programming, 
Now I am in the challenge of obtaining the screen resolution or screens of a remote computer. 
For this I use:
----------------------------------------------------------------------------------------------------------------------------------
Add-Type -AssemblyName System.Windows.Forms 
[System.Windows.Forms.Screen]::AllScreens 
---------------------------------------------------------------------------------------------------------------------------------- 
Which works fine for me on my computer with its two screens or monitors. 
The problem arises when I want to do it on another computer in the domain.
 To do this, I generate the following Script on the Remote-PC, and execute it:  
---------------------------------------------------------------------------------------------------------------------------------- 
# Script to run, 
#  \\$WNOMBRE_PC\C$\temp\Test_Resoluciones.PS1
 
Add-Type -AssemblyName System.Windows.Forms

$WRES_PANT = [System.Windows.Forms.Screen]::AllScreens
$WRES_PANT | Out-File -FilePath "c:\temp\ResolucionesPantalla.txt" `
                      -Encoding default -Force
# End Script
---------------------------------------------------------------------------------------------------------------------------------- 
To run it I use:
---------------------------------------------------------------------------------------------------------------------------------- 
$WSCRIPT_PS1 = '\\' + $WNOMBRE_PC + '\C$\temp\Test_Resoluciones.PS1' 
$WPC_REMOTO  = '\\' + $WNOMBRE_PC 
C:\Windows\SysWOW64\psexec.exe -i -s $WPC_REMOTO PowerShell.exe `
                                     -ExecutionPolicy Bypass `
                                     -WindowStyle Hidden `
                                     -File $WSCRIPT_PS1  
---------------------------------------------------------------------------------------------------------------------------------- 
But the results are nothing like reality. 
So now I'm trying to run it with 
Invoke-command + Start-Process, 
elevating the environment to administrator:
---------------------------------------------------------------------------------------------------------------------------------- 
Invoke-Command -ComputerName $WNOMBRE_PC `
               -scriptBlock { Start-Process -FilePath powershell.exe `
                                   -ArgumentList $Using:WSCRIPT_PS1 `
                                   -Verb Runas `
                                   -WindowStyle Hidden }
----------------------------------------------------------------------------------------------------------------------------------
But here I can't get the script to run. Somebody could help me?

Please do not mix text and code!!

You are overcomplicating this a lot. This should be enough:

Invoke-Command -ComputerName $WNOMBRE_PC -ScriptBlock { 
    Add-Type -AssemblyName System.Windows.Forms
    [System.Windows.Forms.Screen]::AllScreens
} | 
Out-File -FilePath 'c:\temp\ResolucionesPantalla.txt' -Force

Regardless of that: it is considered very bad style to use backticks as line continuation characters. There are a number of ways to make your code better readable. Using backticks is not one of them. You may read more about here:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.