PowerShell for IT Professionals [#6] – Filtering output

Exercises List all services that are stopped List all service that are stopped and they name begins with W Display only the Display Name of services that stopped and their name begins with W Lesson notes ### Filtering # Some commands accept wild cards in the search or have a filter parameter Get-Service -Name w*,b* #But there's more universal method, based on property names Get-Service | Where-Object -Filter {$_.Status -eq 'running' } #So let's break it down #Where-Object allows to filter out the incoming object based on the comparation operator #Most popular operators are: -eq - Equals -ne - Not equals -gt - Greather than -lt - Less then -le - Less than or equal -ge - Greater than or equal -Like -Notlike #There are more many, you can check these help topics: Help about_Operators Help about_Comparison_Operators #$_ is current object; it's what we're piping in our case Get-Service # ....

7 August 2020 · 2 min · 291 words · Kamil

PowerShell for IT Professionals [#5] – Providers

Exercises Create a folder in root of C: with the name of PowerShell Create a file inside the folder with the name of your choice and no content Retrieve all items from Env: drive Check the version of Notepad.exe in Windows directory Discover current Windows build version by registry property: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion Notes from the lesson # Provider allows to access some data storage (e.g. File system, registry, remote system, Active Directory) # This concept might sound a bit abstract at first, but becomes very straight forward once you've used it for a while # Provider once connected to the data storage, kind of "mounts" it like a network drive, allowing to browse and manage it # Once the storage is mounted PowerShell creates so called PSDrive # Let's review available providers Get-Psprovider # Let's review some PSDrives Get-PSDrive # A quick refresher how file system is organised: Drives, Folders, Files # Since PowerShell connects to many different file data storages, it uses the generic term Item and specifies with type....

4 August 2020 · 2 min · 418 words · Kamil

PowerShell for IT Professionals [#4] – Pipeline

Exercises There’s one particular command that allows you output anything from shell to file, find that command and use with any commands like Get-Service or Get-Process. Does it behave differently than Export-CSV? Programs often use CSV but don’t use comma for delimiter – try to exporting to CSV but change the delimiter Can you print directly from shell? See if there are any commands available and if so, print some Event Logs!...

30 July 2020 · 2 min · 259 words · Kamil

PowerShell for IT Professionals [#3] – Running Commands

Exercises Display a list of all services that start with the letter W Display all processes (you might need to use Help to discover the right command. Remember the noun might be singular). Open Notepad (you can simply punch in notepad in the shell) Display only processes that have a name “Notepad” Once you can there’s only one instance of Notepad running, close it with PowerShell! (Verb would be Stop) Confirm with Shell there are no more Notepad processes running Display last 10 lines of C:\windows\setupact....

27 July 2020 · 2 min · 257 words · Kamil

PowerShell for IT Professionals [#1] [#2] – Help

About files solve issue If after running Update-Help you don’t have About topics, you might want to manually download them and extract the archive to the root of: C:\Windows\System32\WindowsPowerShell\v1.0\en PowerShell help – Exercises PowerShell is great in working with CSV files. Can you find help for any CSV related commands (you will need to use a wildcard) Can you tell what’s a difference between ConvertTo-CSV and Export-CSV commands We often need to review event logs – which command would allow you to retrieve event logs?...

23 July 2020 · 1 min · 147 words · Kamil