{"id":1084,"date":"2025-09-06T14:46:49","date_gmt":"2025-09-06T14:46:49","guid":{"rendered":"https:\/\/davidka.net\/?p=1084"},"modified":"2025-09-21T04:47:04","modified_gmt":"2025-09-21T02:47:04","slug":"powershell-philosophy-part-4","status":"publish","type":"post","link":"https:\/\/it.davidka.net\/it\/powershell-philosophy-part-4\/","title":{"rendered":""},"content":{"rendered":"\n<div id=\"rtoc-mokuji-wrapper\" class=\"rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default\" data-id=\"1084\" data-theme=\"Neve - Davidka\">\n\t\t\t<div id=\"rtoc-mokuji-title\" class=\"rtoc_btn_none rtoc_left\">\n\t\t\t\n\t\t\t<span>In Questo Articolo<\/span>\n\t\t\t<\/div><ol class=\"rtoc-mokuji decimal_ol level-1\"><li class=\"rtoc-item\"><a href=\"#rtoc-1\">Part 4: Interactive Work: <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code>, Alerts.<\/a><ul class=\"rtoc-mokuji mokuji_ul level-2\"><li class=\"rtoc-item\"><a href=\"#rtoc-2\">Chapter One: Interactive Work with Data in the Console.<\/a><ul class=\"rtoc-mokuji mokuji_none level-3\"><li class=\"rtoc-item\"><a href=\"#rtoc-3\"><code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code>. GUI in PowerShell Console.<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-4\">What <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code> can do:<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-5\">Examples of using <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code><\/a><ul class=\"rtoc-mokuji mokuji_ul level-2\"><li class=\"rtoc-item\"><a href=\"#rtoc-6\">Basic usage \u2014 show a table with interactive selection capability. (checkbox)<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-7\">Selecting a single row with mandatory result return. (radio)<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-8\">Filtering and sorting large arrays<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-9\">Interactive process management:<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-10\">Selecting files for archiving:<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-11\">Selecting a single item for detailed analysis:<\/a><ul class=\"rtoc-mokuji mokuji_none level-3\"><li class=\"rtoc-item\"><a href=\"#rtoc-12\">&#8220;Drill-Down&#8221; Pattern \u2014 from general list to details with <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code><\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-13\">Practical example: Creating a network adapter explorer<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-14\">Step-by-step breakdown<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-15\">Example with custom title and hints<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-16\">System Information.<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-17\">Creating the &#8216;Get-SystemMonitor&#8217; cmdlet<\/a><ul class=\"rtoc-mokuji mokuji_none level-3\"><li class=\"rtoc-item\"><a href=\"#rtoc-18\">Step 1: Setting up the <code class=\"\" data-line=\"\">PATH<\/code> variable<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-19\">Step 2: Setting up an alias in the PowerShell profile<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-20\">Restart PowerShell<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-21\">Result: What you get<\/a><\/li><\/ul><\/li><\/ol><\/div><h2 id=\"rtoc-1\"  class=\"wp-block-heading\">Part 4: Interactive Work: <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code>, Alerts.<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In <a href=\"https:\/\/github.com\/hypo69\/The-Philosophy-of-PowerShell-ru\/blob\/master\/01.md\">Part 1<\/a> we defined two key PowerShell concepts: pipeline and object.<\/li>\n\n\n\n<li>In <a href=\"https:\/\/github.com\/hypo69\/The-Philosophy-of-PowerShell-ru\/blob\/master\/02.md\">Part 2<\/a> I explained what objects and pipelines are.<\/li>\n\n\n\n<li>In <a href=\"https:\/\/github.com\/hypo69\/The-Philosophy-of-PowerShell-ru\/blob\/master\/03.md\">Part 3<\/a> we got acquainted with the file system and providers.<\/li>\n\n\n\n<li>Today we will look at interactive work with data in the console, as well as get acquainted with alerts and notifications.<\/li>\n<\/ul>\n\n\n\n<h3 id=\"rtoc-2\"  class=\"wp-block-heading\">Chapter One: Interactive Work with Data in the Console.<\/h3>\n\n\n\n<h4 id=\"rtoc-3\"  class=\"wp-block-heading\"><code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code>. GUI in PowerShell Console.<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u2757 Important:<\/strong> All tools described below require <strong>PowerShell 7.2 or newer<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code> is an interactive table, directly in the PowerShell console, allowing you to: &#8211; view data in a table; &#8211; filter and sort columns; &#8211; select rows with the cursor \u2014 to pass them further down the pipeline. &#8211; and much more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code> is part of the <code class=\"\" data-line=\"\">Microsoft.PowerShell.ConsoleGuiTools<\/code> module. To use it, you first need to install this module.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To install the module, run the following command in PowerShell:<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">Install-Module Microsoft.PowerShell.ConsoleGuiTools -Scope CurrentUser\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"assets\/04\/1.png\" alt=\"Install-Module Microsoft.PowerShell.ConsoleGuiTools -Scope CurrentUser\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Install-Module<\/em> downloads and installs the specified module from the repository to the system. Analogues: <code class=\"\" data-line=\"\">pip install<\/code> in <code class=\"\" data-line=\"\">Python<\/code> or <code class=\"\" data-line=\"\">npm install<\/code> in <code class=\"\" data-line=\"\">Node.js<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udcce Key parameters of <em>Install-Module<\/em><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Parameter<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code class=\"\" data-line=\"\">-Name<\/code><\/td><td>The name of the module to install.<\/td><\/tr><tr><td><code class=\"\" data-line=\"\">-Scope<\/code><\/td><td>Installation scope: <code class=\"\" data-line=\"\">AllUsers<\/code> (default, requires administrator rights) or <code class=\"\" data-line=\"\">CurrentUser<\/code> (does not require administrator rights).<\/td><\/tr><tr><td><code class=\"\" data-line=\"\">-Repository<\/code><\/td><td>Specifies the repository, for example <code class=\"\" data-line=\"\">PSGallery<\/code>.<\/td><\/tr><tr><td><code class=\"\" data-line=\"\">-Force<\/code><\/td><td>Forced installation without confirmation.<\/td><\/tr><tr><td><code class=\"\" data-line=\"\">-AllowClobber<\/code><\/td><td>Allows overwriting existing commands.<\/td><\/tr><tr><td><code class=\"\" data-line=\"\">-AcceptLicense<\/code><\/td><td>Automatically accepts the module license.<\/td><\/tr><tr><td><code class=\"\" data-line=\"\">-RequiredVersion<\/code><\/td><td>Installs a specific version of the module.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, you can pipe any output to <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code> for interactive work.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\"># Classic example: displaying a list of processes in an interactive table\nGet-Process | Out-ConsoleGridView\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/user-attachments\/assets\/5828dd51-cfb8-4904-87be-796ccc8395be\">1<\/a><video width=\"600\" controls=\"\"><\/video><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Interface:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Filtering:<\/strong> Just start typing, and the list will be filtered on the fly.<\/li>\n\n\n\n<li><strong>Navigation:<\/strong> Use arrow keys to move through the list.<\/li>\n\n\n\n<li><strong>Selection:<\/strong> Press <code class=\"\" data-line=\"\">Space<\/code> to select\/deselect an item.<\/li>\n\n\n\n<li><strong>Multiple selection:<\/strong> <code class=\"\" data-line=\"\">Ctrl+A<\/code> to select all items, <code class=\"\" data-line=\"\">Ctrl+D<\/code> to deselect all.<\/li>\n\n\n\n<li><strong>Confirmation:<\/strong> Press <code class=\"\" data-line=\"\">Enter<\/code> to return the selected objects.<\/li>\n\n\n\n<li><strong>Cancel:<\/strong> Press <code class=\"\" data-line=\"\">ESC<\/code> to close the window without returning data.<\/li>\n<\/ul>\n\n\n\n<h3 id=\"rtoc-4\"  class=\"wp-block-heading\">What <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code> can do:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Display tabular data directly in the PowerShell console as an interactive table with row and column navigation.<\/li>\n\n\n\n<li>Sort columns by pressing keys.<\/li>\n\n\n\n<li>Filter data using search.<\/li>\n\n\n\n<li>Select one or more rows with result return.<\/li>\n\n\n\n<li>Work in a clean console without GUI windows.<\/li>\n\n\n\n<li>Support a large number of rows with scrolling.<\/li>\n\n\n\n<li>Support various data types (strings, numbers, dates, etc.).<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"rtoc-5\"  class=\"wp-block-heading\">Examples of using <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code><\/h2>\n\n\n\n<h3 id=\"rtoc-6\"  class=\"wp-block-heading\">Basic usage \u2014 show a table with interactive selection capability. (checkbox)<\/h3>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">Import-Module Microsoft.PowerShell.ConsoleGuiTools\n\n$data = Get-Process | Select-Object -First 30 -Property Id, ProcessName, CPU, WorkingSet\n\n# Display a table with filtering, sorting, and row selection capabilities\n$selected = $data | Out-ConsoleGridView -Title &quot;Select process(es)&quot; -OutputMode Multiple\n\n$selected | Format-Table -AutoSize\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/user-attachments\/assets\/3f1a2a62-066f-4dbb-947a-9b26095da356\">2<\/a><video><\/video><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The list of processes is displayed in an interactive console table. You can filter by name, sort columns, and select processes. Selected processes are returned to the <code class=\"\" data-line=\"\">$selected<\/code> variable.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-7\"  class=\"wp-block-heading\">Selecting a single row with mandatory result return. (radio)<\/h3>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">$choice = Get-Service | Select-Object -First 20 | Out-ConsoleGridView -Title &quot;Select a service&quot; -OutputMode Single\n\nWrite-Host &quot;You selected service: $($choice.Name)&quot;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/user-attachments\/assets\/5ee8fb92-8e18-496a-9db7-2d86b243742e\"><\/a><video><\/video><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">User selects a single row (service). <code class=\"\" data-line=\"\">-OutputMode Single<\/code> prevents multiple selections.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-8\"  class=\"wp-block-heading\">Filtering and sorting large arrays<\/h3>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">$data = 1..1000 | ForEach-Object { \n    &#091;PSCustomObject]@{ \n        Number = $_ \n        Square = $_ * $_ \n        Cube   = $_ * $_ * $_ \n    } \n}\n\n$data | Out-ConsoleGridView -Title &quot;Numbers and powers&quot;  -OutputMode Multiple\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Displays a table of 1000 rows with numbers and their powers.<\/p>\n\n\n\n<h3 id=\"rtoc-9\"  class=\"wp-block-heading\"><strong>Interactive process management:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can select multiple processes to stop. The <code class=\"\" data-line=\"\">-OutputMode Multiple<\/code> parameter indicates that we want to return all selected items.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\"># Pipe the results.\n# Stop selected processes with the -WhatIf parameter for preview.\n# To do this, define the $procsToStop variable\n$procsToStop = Get-Process | Out-ConsoleGridView -OutputMode Multiple\n\n# If something was selected, pass the objects further down the pipeline\nif ($procsToStop) {\n    $procsToStop | Stop-Process -WhatIf\n}\n<\/code><\/pre>\n\n\n\n<h3 id=\"rtoc-10\"  class=\"wp-block-heading\"><strong>Selecting files for archiving:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Find all <code class=\"\" data-line=\"\">.log<\/code> files in a folder, select the necessary ones, and create an archive from them.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">$filesToArchive = Get-ChildItem -Path C:\\Logs -Filter &quot;*.log&quot; -Recurse | Out-ConsoleGridView -OutputMode Multiple\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2757Be careful with recursion<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">if ($filesToArchive) {\n    Compress-Archive -Path $filesToArchive.FullName -DestinationPath C:\\Temp\\LogArchive.zip\n\n    # Add success message\n    Write-Host &quot;\u2705 Archiving completed successfully!&quot; -ForegroundColor Green\n}\n<\/code><\/pre>\n\n\n\n<h3 id=\"rtoc-11\"  class=\"wp-block-heading\"><strong>Selecting a single item for detailed analysis:<\/strong><\/h3>\n\n\n\n<h4 id=\"rtoc-12\"  class=\"wp-block-heading\">&#8220;Drill-Down&#8221; Pattern \u2014 from general list to details with <code class=\"\" data-line=\"\">Out-ConsoleGridView<\/code><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Often when working with system objects, we face a dilemma:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>If you request <strong>all properties<\/strong> for <strong>all objects<\/strong> (<code class=\"\" data-line=\"\">Get-NetAdapter | Format-List *<\/code>), the output will be huge and unreadable.<\/li>\n\n\n\n<li>If you show a <strong>brief table<\/strong>, we will lose important details.<\/li>\n\n\n\n<li>Sometimes trying to get all data at once can lead to an error if one of the objects contains invalid values.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Solving this problem is the <strong>&#8220;Drill-Down&#8221;<\/strong> pattern (detailing or &#8220;drilling down&#8221;). Its essence is simple:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 1 (Overview):<\/strong> Show the user a clean, concise, and safe list of items for <strong>selection<\/strong>.<\/li>\n\n\n\n<li><strong>Step 2 (Detailing):<\/strong> After the user has selected one specific item, show them <strong>all available information<\/strong> for that particular item.<\/li>\n<\/ul>\n\n\n\n<h4 id=\"rtoc-13\"  class=\"wp-block-heading\">Practical example: Creating a network adapter explorer<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s implement this pattern using the <code class=\"\" data-line=\"\">Get-NetAdapter<\/code> command as an example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Task:<\/strong> First, show a brief list of network adapters. After selecting one of them, open a second window with all its properties.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ready code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\"># --- Stage 1: Selecting an adapter from a brief list ---\n$adapterList = Get-NetAdapter | Select-Object Name, InterfaceDescription, Status, LinkSpeed\n$selectedAdapter = $adapterList | Out-ConsoleGridView -Title &quot;STAGE 1: Select a network adapter&quot;\n\n# --- Stage 2: Displaying detailed information or a cancellation message ---\nif ($null -ne $selectedAdapter) {\n    # Get ALL properties for the SELECTED adapter\n    $detailedInfoObject = Get-NetAdapter -Name $selectedAdapter.Name | Select-Object *\n\n    # Use our trick with .psobject.Properties to turn the object into a convenient &quot;Name-Value&quot; table\n    $detailedInfoForGrid = $detailedInfoObject.psobject.Properties | Select-Object Name, Value\n\n    # Open a SECOND GridView window with full information\n    $detailedInfoForGrid | Out-ConsoleGridView -Title &quot;STAGE 2: Full information for &#039;$($selectedAdapter.Name)&#039;&quot;\n} else {\n    Write-Host &quot;Operation canceled. Adapter was not selected.&quot; -ForegroundColor Yellow\n}\n<\/code><\/pre>\n\n\n\n<h4 id=\"rtoc-14\"  class=\"wp-block-heading\">Step-by-step breakdown<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Creating a &#8220;safe&#8221; list:<\/strong> <code class=\"\" data-line=\"\">$adapterList = Get-NetAdapter | Select-Object Name, InterfaceDescription, Status, LinkSpeed<\/code> We do not pipe the output of <code class=\"\" data-line=\"\">Get-NetAdapter<\/code> directly. Instead, we create new, &#8220;clean&#8221; objects using <code class=\"\" data-line=\"\">Select-Object<\/code>, including only the properties we need for an overview. This ensures that problematic data that caused an error will be discarded.<\/li>\n\n\n\n<li><strong>First interactive window:<\/strong> <code class=\"\" data-line=\"\">$selectedAdapter = $adapterList | Out-ConsoleGridView ...<\/code> The script displays the first window and <strong>pauses its execution<\/strong>, waiting for your selection. Once you select a row and press <code class=\"\" data-line=\"\">Enter<\/code>, the object corresponding to that row will be written to the <code class=\"\" data-line=\"\">$selectedAdapter<\/code> variable.<\/li>\n\n\n\n<li><strong>Checking the selection:<\/strong> <code class=\"\" data-line=\"\">if ($null -ne $selectedAdapter)<\/code> This is a critically important check. If the user presses <code class=\"\" data-line=\"\">Esc<\/code> or closes the window, the <code class=\"\" data-line=\"\">$selectedAdapter<\/code> variable will be empty (<code class=\"\" data-line=\"\">$null<\/code>). This check prevents the rest of the code from executing and errors from occurring.<\/li>\n\n\n\n<li><strong>Getting full information:<\/strong> <code class=\"\" data-line=\"\">$detailedInfoObject = Get-NetAdapter -Name $selectedAdapter.Name<\/code> Here&#8217;s the key point of the pattern. We call <code class=\"\" data-line=\"\">Get-NetAdapter<\/code> again, but this time we request <strong>only one<\/strong> object by its name, which we took from the item selected in the first stage. Now we get the full object with all its properties.<\/li>\n\n\n\n<li><strong>Transformation for the second window:<\/strong> <code class=\"\" data-line=\"\">$detailedInfoForGrid = $detailedInfoObject.psobject.Properties | ...<\/code> We use the powerful trick you already know to &#8220;unroll&#8221; this single complex object into a long list of &#8220;Property Name&#8221; | &#8220;Value&#8221; pairs, which is ideal for display in a table.<\/li>\n\n\n\n<li><strong>Second interactive window:<\/strong> <code class=\"\" data-line=\"\">$detailedInfoForGrid | Out-ConsoleGridView ...<\/code> A second window appears on the screen, this time with comprehensive information about the adapter you selected.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-15\"  class=\"wp-block-heading\">Example with custom title and hints<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Displaying Windows event log in an interactive table with the title &#8220;System Events&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">Get-EventLog -LogName System -Newest 50 |\n    Select-Object TimeGenerated, EntryType, Source, Message |\n    Out-ConsoleGridView -Title &quot;System Events&quot;  -OutputMode Multiple\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This code retrieves the last 50 events from the Windows system log, selects only four key properties (time, type, source, and message) from each event, and displays them in the Out-ConsoleGridView window.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-16\"  class=\"wp-block-heading\">System Information.<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/user-attachments\/assets\/1e53a339-56f9-4add-8053-86d94dbc8e06\">1<\/a><video width=\"600\" controls=\"\"><\/video><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code for the system information script: <a href=\"https:\/\/github.com\/hypo69\/The-Philosophy-of-PowerShell-ru\/blob\/master\/code\/04\/Get-SystemMonitor.ps1\">Get-SystemMonitor.ps1<\/a><\/p>\n\n\n\n<h3 id=\"rtoc-17\"  class=\"wp-block-heading\">Creating the &#8216;Get-SystemMonitor&#8217; cmdlet<\/h3>\n\n\n\n<h4 id=\"rtoc-18\"  class=\"wp-block-heading\">Step 1: Setting up the <code class=\"\" data-line=\"\">PATH<\/code> variable<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create a permanent folder for your tools,<\/strong> if you haven&#8217;t already. For example: <code class=\"\" data-line=\"\">C:\\PowerShell\\Scripts<\/code><\/li>\n\n\n\n<li><strong>Place your <code class=\"\" data-line=\"\">Get-SystemMonitor.ps1<\/code> file<\/strong> in this folder.<\/li>\n\n\n\n<li><strong>Add this folder to the system <code class=\"\" data-line=\"\">PATH<\/code> variable<\/strong>,<\/li>\n<\/ol>\n\n\n\n<h4 id=\"rtoc-19\"  class=\"wp-block-heading\">Step 2: Setting up an alias in the PowerShell profile<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the system knows where to find your script by its full name, we can create a short alias for it.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Open your PowerShell profile file<\/strong>: <code class=\"\" data-line=\"\">notepad $PROFILE<\/code><\/li>\n\n\n\n<li><strong>Add the following line to it:<\/strong> <code class=\"\" data-line=\"\"># Alias for system monitor Set-Alias -Name sysmon -Value &quot;Get-SystemMonitor.ps1&quot;<\/code> <strong>Note the key point:<\/strong> Since the folder with the script is already in <code class=\"\" data-line=\"\">PATH<\/code>, we no longer need to specify the full path to the file! We simply refer to its name. This makes your profile cleaner and more reliable. If you ever move the <code class=\"\" data-line=\"\">C:\\PowerShell\\Scripts<\/code> folder, you will only need to update the <code class=\"\" data-line=\"\">PATH<\/code> variable, and your profile file will remain unchanged.<\/li>\n<\/ol>\n\n\n\n<h4 id=\"rtoc-20\"  class=\"wp-block-heading\">Restart PowerShell<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Close <strong>all<\/strong> open PowerShell windows and open a new one. This is necessary for the system to apply changes to both the <code class=\"\" data-line=\"\">PATH<\/code> variable and your profile.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-21\"  class=\"wp-block-heading\">Result: What you get<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After performing these steps, you will be able to call your script <strong>in two ways from anywhere in the system<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>By full name (reliable, for use in other scripts):<\/strong> <code class=\"\" data-line=\"\">Get-SystemMonitor.ps1 Get-SystemMonitor.ps1 -Resource storage<\/code><\/li>\n\n\n\n<li><strong>By short alias (convenient, for interactive work):<\/strong> <code class=\"\" data-line=\"\">sysmon sysmon -Resource memory<\/code><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">You have successfully &#8220;registered&#8221; your script in the system in the most professional and flexible way.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Useful? Subscribe. Liked it \u2014 put &#8220;+&#8221; Good luck! \ud83d\ude80<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Other PowerShell articles:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Questo Articolo Part 4: Interactive Work: Out-ConsoleGridView, Alerts. Chapter One: Interactive Work with Data in the Console. Out-ConsoleGridView. GUI in PowerShell Console. What Out-ConsoleGridView can do: Examples of using Out-ConsoleGridView Basic usage \u2014 show a table with interactive selection capability. (checkbox) Selecting a single row with mandatory result return. (radio) Filtering and sorting large&hellip;&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":2899,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"left","neve_meta_author_avatar":"","neve_post_elements_order":"[\"content\",\"tags\",\"comments\"]","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[624,1],"tags":[765],"class_list":["post-1084","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-uncategorized","tag-ms-powershell"],"acf":[],"_links":{"self":[{"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/posts\/1084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/comments?post=1084"}],"version-history":[{"count":0,"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/posts\/1084\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/media\/2899"}],"wp:attachment":[{"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/media?parent=1084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/categories?post=1084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.davidka.net\/it\/wp-json\/wp\/v2\/tags?post=1084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}