/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Powershell Output not showing

07/02/2018 836 views

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?

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

Do{
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

do
{
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')

0 Comments   [ + ] Show comments

Comments


All Answers

0

Try this below. You almost had it.

https://pastebin.com/LQf9Hit3


This is not the best way to script but if you are learning, its OK. The best method would be to have array feed into a script/code that has all the machines with the desired setting - aiming for full automation.

Anything that waits for a action or sleeps is undesired - keep that in mind when you advance (:


$DebugPreference = 'SilentlyContinue' #SilentlyContinue|Continue
#Dont clear host, its nice to have a trace
[String]$ComputerName = Read-Host "PC Name"
If ((Test-Connection -count 1 $ComputerName -Quiet) -eq $false)
    {Do {Write-Warning "Can not contact '$ComputerName'."
         $strQuit = Read-Host "Do you want to test again? (Y/N)"}
         Until ($strQuit -eq 'N')}
     If ($strQuit -eq 'N')
         {$strQuit = $null #Clearing var so you can rerun again with out issues.
          Throw} #Ugly Stop
Else{$DriverData = Get-WmiObject Win32_VideoController -ComputerName localhost | select SystemName, Description, DriverVersion}

Do {#Write-Host "         $($DriverData.SystemName)"
    Write-Host "         $($DriverData.Description)"
    Write-Host "         $($DriverData.DriverVersion)"
    Write-Host "1: Clone"
    Write-Host "2: Extend"
    $input = Read-Host "Please make a selection"
    switch ($input) {'1' {Invoke-Command -ComputerName $ComputerName -ScriptBlock {C:\Windows\System32\DisplaySwitch.exe /clone}
                          Write-Debug 'Clone'}
                     '2' {Invoke-Command -ComputerName $ComputerName -ScriptBlock {C:\Windows\System32\DisplaySwitch.exe /extend}
                          Write-Debug 'Extend'}}
                         
    Write-Debug "`$input is $input"}
   
Until (($input -eq '1') -or ($input -eq '2'))


Answered 07/03/2018 by: rileyz
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ