This Github repo is for the cours OS (operating systems) in ITFactory at Thomasmore Geel.
The goal is to learn use ing powershell and windows in my case making a script using Pester Test (infrastructure test).
This documentation was made with and for windows 10 enterprise. And goes over the folowing things.
- NAT networking in Virtual Box is switched on
- Whether an Internet connection is possible
- Whether a username with the name "admin" exists
- Whether the firewall is on
- Whether the virtual box guest additions are installed in the virtual machine.
- How long your device can work with a trial edition.
- If the keyboard layout "Belgian (period) is in the LanguageList.
And
- Whether VSCode is installed.
- Whether VSCode is running
- Whether https://sinners.be is available.
At the end of the Pester test, write information about your Pester test to one of the log files in event viewer.
Don't forget Get-Member !!! it exists.
Pester is a testing and mocking framework for PowerShell.
Pester provides a framework for writing and running tests. Pester is most commonly used for writing unit and integration tests, but it is not limited to just that. It is also a base for tools that validate whole environments, computer deployments, database configurations and so on. Readmore.
A peter test should are structured like this.
Describe 'Name of the test' {
It 'What its checking for' {
Testscript or command |
Should Be $true #, $false a number (greater then, less then, equel to )
}
# There can be multiple test in 1 Describe.
It 'What its checking for' {
Testscript or command |
Should Be $true
}
}
Test if the 'Default gateway' add 10.0.2.2 is available if it is that means the NAT network adapter is correctly connected.
Test-Connection -ComputerName 10.0.2.2 -Quiet -Count 1
Test if the google DNS servers are available.
Test-Connection -ComputerName 8.8.8.8 -Quiet -Count 1
Test if the username is present, by geting the localuser list and testing for the name.
Get-LocalUser $USERNAME |Select-Object name | should be "@{Name=$USERNAME}"
This command geteds the list of firewalls and filters the (Public, private and Domain) and checks if Enabled is true.
Get-NetFirewallProfile | where-object {$_.Profile -like "Public"} | Select-Object Enabled | should be "@{Enabled=True}"
Test if the VirtualBox Guest Additions are installed
get-package "Oracle VM VirtualBox Guest Additions 7.0.12"
This command gets the SoftwareLicensingProduct object then looks at the graceperiod in it in days rounds to a full day and tests if ist greater than 0
$info = Get-CimInstance -ClassName SoftwareLicensingProduct
[math]::Round($($info.GracePeriodRemaining/24/60), 0) |
should BeGreaterThan 0
I did not get this to work. Where-Object can not filter on Languagetag.
Get-WinUserLanguageList | Where-Object {$_.Languagetag -like "nl-BE"}
And
Get-WinUserLanguageList
Return the same list:
LanguageTag : en-BE
Autonym : English (Belgium)
EnglishName : English
LocalizedName : English (Belgium)
ScriptName : Latin
InputMethodTips : {}
Spellchecking : True
Handwriting : False
LanguageTag : nl-BE
Autonym : Nederlands (België)
EnglishName : Dutch
LocalizedName : Dutch (Belgium)
ScriptName : Latin
InputMethodTips : {0813:00000813}
Spellchecking : True
Handwriting : False
Test if the package Visual Studio Code is installed
get-package "Microsoft Visual Studio Code (user)"
check the processes list for the processname "code" this is the process name for vscode.
Get-Process "code"
Checking if a local user account/ group exists or not with Powershell
Use PowerShell to Check the License Status of Windows 8