Archive

Posts Tagged ‘foreach’

PowerShell: Get information for an update installation when it is started, finished, and how long take

09 August 2018 Leave a comment

Microsoft’s updates never end. According to some system administrators, this is a headache. According to some system administrators, it is necessary for security. Although you are working with too many updates, in some cases you may need detailed information about the update installation. When did the update begin? When was the update installed? How long was the update set up?

PowerShell_ISE
In such situations grab the PowerShell help 🙂
The following codes fetch this information about the update you specified from the machine’s EventView logs.

Update_Installation

$eventt=Get-WinEvent -FilterHashtable @{Logname = ‘setup’; id = 1} |
Select Message, Timecreated | Select-String -Pattern ‘KB4339420\d*’ –AllMatches

$eventt |
foreach{
$zaman=(($_.line).split(“;”)[1].split(” “)[2]).replace(“}”,””)
$KB2=$_.matches
$kb=$kb2 | foreach{$_.value}
Write-host $KB “Installation start time” $zaman
}

$eventt2=Get-WinEvent -FilterHashtable @{Logname = ‘setup’; id = 4} |
Select Message, Timecreated | Select-String -Pattern ‘KB4339420\d*’ –AllMatches

$eventt2 |
foreach{
$zaman2=(($_.line).split(“;”)[1].split(” “)[2]).replace(“}”,””)
$KB4=$_.matches
$kb3=$kb4 | foreach{$_.value}
Write-host $KB3 “Installation finish time” $zaman2
[timespan]$sonuc=[timespan]$zaman2-[timespan]$zaman
write-host $KB3 ” update installed in ” $sonuc.minutes “minute(s) and ” $sonuc.seconds “second(s)”
}

Note: I have set these codes so that they get information for the update that was set up during the day. If you need information for a different day, you may need to make changes.

Advertisements

Test multiple URLs with PowerShell Script

If you are a web application administrator or you are building infrastructure, you may need to work with many URLs and test them at the same time.

This script allows you to create URLs with .txt documents or web address parameters you write and test them with Internet Explorer or Chrome. It also allows you to get test results as .log.

Please do not hesitate to contact me if you need a similar script or if you have any problems.
Do not forget to follow 🙂

2018-06-27_11-51-29

#Script starts here

#Get country and language codes with fr/fr format
#$counlang = Get-Content ‘C:\script\counlang.txt’
# Test Country and Language
$counlang = “noo/no”,”no/no”,”fi/en”,”fi/tr”

Read more…

Get windows registry value from remote computer

If you manage a large domain network. Your manager may ask you for information about the applications that are installed on the systems at certain intervals. This program can be more important for this company if it is an expensive application.

In the following example, we try to determine which machines have visual studio by collecting registry key information

Goal: Read registry value from remote machine

Source: Read remote machine names from .txt file

Result: Get results in .csv format

Read more…