Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Adding Test-Connection to my script

$
0
0

Greetings,

I was helped with creating the script below.  I've added a bit more like version of IE and whether a specific KB was installed.

I typically run a separate script to print the computers and then the once that are alive with this script.   Its now a hassle.

Currently if the PC is not alive, it messes up the script and it seems to run forever.

I want to add Test-Connection to combine both scripts.

I tried adding Test-Connection but I don't know where to add it and what to add inside the script block.

You assistance is greatly appreciated.

Thank you

 $array=@()

$keynameIE='SOFTWARE\\Microsoft\\Internet Explorer'
$keynameUser='SOFTWARE\\Microsoft\\Windows\CurrentVersion\\Authentication\\LogonUI'

# $computernames = Get-Content -Path 'C:\Users\ItsMe\Documents\Projects\IE-11-Upgrade-Test\Computers-IE-Deployment-Test.csv'
$ComputerNames=Get-Content-Path'C:\Users\ItsMe\Desktop\Computers.txt'


$SavePath='C:\Users\ItsMe\Documents\Projects\IE-11-Upgrade'

$Date=Get-Date-FormatMMM-dd-yyyy
$Time=Get-Date-Formathh-mm-ss

foreach ($serverin$computernames)
{
$reg= [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$server)
$key=$reg.OpenSubkey($keynameIE)
$value=$key.GetValue('svcVersion')

$key1=$reg.OpenSubkey($keynameUser)
$value1=$key1.GetValue('LastLoggedOnSAMUser')

$HotFix=Get-HotFix-ID KB3078071 -ComputerName$server | Select InstalledOn
$HotFix1=Get-HotFix-ID KB3087985 -ComputerName$server | Select InstalledOn

$obj=New-Object PSObject

$obj | Add-Member-MemberType NoteProperty -Name"ComputerName"-Value$server

$obj | Add-Member-MemberType NoteProperty -Name"IEVersion"-Value$value

# $obj | Add-Member -MemberType NoteProperty -Name "CurrentUser" -Value "Value"

$obj | Add-Member-MemberType NoteProperty -Name"LastLoggedOnSAMUser"-Value$value1

$obj | Add-Member-MemberType NoteProperty -Name"KB3078071"-Value"$HotFix"

$obj | Add-Member-MemberType NoteProperty -Name"KB3087985"-Value"$HotFix1"

$array+=$obj


}

$array | select ComputerName,IEVersion,LastLoggedOnSAMUser,KB3078071,KB3087985 | export-csv-Path$SavePath\Computers-IE-Deployment-Test-Results-$Date--$Time.csv-NoTypeInformation


Viewing all articles
Browse latest Browse all 6937

Trending Articles