Tag: commandline

PowerShell Predictive IntelliSense

PowerShell Predictive IntelliSense

2020 must have been a busy year because I missed one of the greatest new PowerShell features called Predictive IntelliSense. Back in November 2020, Jason Helmick announced PowerShell PSReadLine 2.1 with Predictive IntelliSense.

Update: PSReadLine version 2.2 is now general available.

One of the first things you learn when using a shell usually is tab completion. Tab provides automatic help when you are typing a command. However, we all know that the world around us gets increasingly complex. For example, the Azure PowerShell module offers over 4000 cmdlets with on average 10 parameters each. While tab-completion often is very helpful, wouldn’t it be great if the shell predicts what I am trying to do, based on my history or even with artificial intelligence (AI) pulled from the documentation? PowerShell Predictive IntelliSense is here to help with exactly that.

PowerShell Predictive IntelliSense
PowerShell Predictive IntelliSense

PowerShell Predictive IntelliSense uses my local command history and suggests the command I want to use. And with the latest version of PSReadLine 2.2.2 it can have additional plugins. These additional providers enhance predictions by providing domain-specific command and task completions, for example, for Azure PowerShell commands.

Keyboard shortcuts

Key bindings control cursor movement and additional features within the prediction. To support ListView, additional key bindings have been added to the Windows edit mode.

F2 is bound with SwitchPredictionView by default for switching between the InlineView and ListView.

Ctrl+z will revert to the original line when a list item is selected and keep the list view.

Escape will revert to the original line, whether a list item is selected, and clear the list view.

UpArrow and DownArrow are used to select an item in the ListView. To navigate history commands while the ListView is present, first press Escape to clear the ListView, then use UpArrow and DownArrow.

With Alt+A you can jump from parameter input to parameter input.

Get started with PowerShell Predictive IntelliSense

Predictive IntelliSense is implemented in the PowerShell engine and presented through the PSReadLine module. You can use the current version, which comes with PowerShell 7.2, or you can use some additional features with the latest beta release.

PSReadLine 2.2.2 + History Based Prediction

PowerShell Predictive IntelliSense InlineView
PowerShell Predictive IntelliSense InlineView

History-based predictions is available in the following versions:

Availability:

  • PSReadLine 2.2.2 currently available for download from PSGallery

Supported PowerShell versions:

Install PSReadLine 2.2.2:

Install-Module PSReadLine -Force

By default Predictive IntelliSense is disabled, you can enable it by running the following commands:

Set-PSReadLineOption -PredictionSource History

PSReadLine Plugin Prediction

PowerShell Predictive IntelliSense ListView
PowerShell Predictive IntelliSense ListView with History and Plugin

Version 2.2.2 brings ListView and a prediction plugin.

Availability:

  • PSReadLine 2.2.2 currently available for download from PSGallery

Supported PowerShell versions for ListView (History-based predictions only):

Supported PowerShell versions for the plugin subsystem (History and plugin predictions):

  • PowerShell 7.2
Install-Module PSReadLine -Force

By default, Predictive IntelliSense is disabled, you can enable it by running the following commands:

Set-PSReadLineOption -PredictionSource HistoryAndPlugin
#OPTIONAL you can also enable ListView
Set-PSReadLineOption -PredictionViewStyle ListView

One of the currently available plugins is Az Predictor, which helps you predict Azure PowerShell cmdlets. I will show you more about Az Predictor next week.

But wait there is more!

In his blog post, Jason Helmick shows even more functionality like:

  • Change the Color for Predictions using.
    Set-PSReadLineOption -Colors @{ InlinePrediction = ‘#8A0303’}
    Set-PSReadLineOption -Colors @{ InlinePrediction = ‘#2F7004’}
    Set-PSReadLineOption -Colors @{ InlinePrediction = “$([char]0x1b)[36;7;238m”}
  • Key Bindings for Predictions (List of additional suggested key bindings defined in PSReadLine SamplePSReadLineProfile.ps1)
  • and much, much more! So make sure you check out his blog post!

PowerShell Predictive IntelliSense Conclusion

I think the PowerShell Predictive IntelliSense feature is one of the best things since sliced bread. It can make you much more productive using PowerShell in so many different ways. And with the additional AI-powered modules, for example, Az Predictor, which kind of reminds me of the Azure CLI “az find” command, will help deal with more complex scenarios.

If you have any questions or comments, feel free to leave a comment below.



Windows Server Core

Commands for Windows Server Core & Hyper-V Server

For some KTSI projects I have been working a lot with Windows Server Core or Hyper-V Server. Now I had to do a lot of automation, so I made this little connection of commands. If you configure the server manually you can do the most important things with the sconfig utility.

Windows Server Core

Networking

Set Hostname

netdom renamecomputer %COMPUTERNAME% /NewName:<NewComputerName>

Join Domain

netdom join %COMPUTERNAME% /domain:<DomainName> /userd:<UserName> /passwordd:*

Remove Domain

netdom remove

Rename Network Interface

netsh interface set interface name=”old name” newname=”new name”

Configure IP Address

netsh interface ipv4 set address name=<Interface Name>” source=static address=<IPAddress> mask=<SubnetMask> gateway=<DefaultGateway>

Configure DNS Servers

netsh interface ipv4 add dnsserver name=<Interface Name>” address=<DNS Server IP> index=1

Disable Firewall (not recommended)

netsh advfirewall set allprofiles state off

 

Remoting

Enable PowerShell Remoting

Enable-PSRemoting

Enable Remotedesktop

netsh advfirewall firewall set rule group=”remote desktop” new enable=yes

Enable Remote Administration

advfirewall firewall set rule group=”Remote Administration” new enable=yes

Enable Remote Firewall Administration

netsh advfirewall firewall set rule group=”Windows Firewall Remote Management” new enable=yes

Enable ICMP (Ping)

netsh firewall set icmpsetting 8

Enable Remote Disk Management

netsh advfirewall firewall set rule group=”Remote Volume Management” new enable=yes

 

Licensing

Enter License key

slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Activate Windows

slmgr.vbs -ato

 

Windows Update

Enable automatic updates

cscript C:'Windows'System32'Scregedit.wsf /au 4

Disable automatic updates

cscript C:'Windows'System32'Scregedit.wsf /au 1

 

Roles & Features

Get availibale features & roles

Dism /online /get-features /format:table

Enable feature & roles

Dism /online /enable-feature /featurename:<featurename>

 

Basics

Change Administrator password

net user administrator *

Restart Computer

shutdown /r /t 0

Logoff

logoff

More information about Server Core: TechNet



Check NTFS Version

If you need to know which version of NTFS you are using you can do that with the fsutil.exe and the following command.

In my case I am testing my C:\ drive:

fsutil fsinfo ntfsinfo c:

fsutil

More on NTFS Versions on wikipedia.



Install HP Support Pack on Hyper-V R2 Core Server

If you are using Microsoft Hyper-V R2 Core Server, installing the HP Support Pack is a little different. This post should show you how this is done.

  1. Download the latest HP Support Pack for Windows Server 2008 R2 and extract that on your Management Server or PC.
  2. Now copy the extracted folder to the Hyper-V Core Server. In my case i copied in the C:\ root of the Core Server via the administrative network share. If you have easy physical access to the server, you could also use a USB stick or something like that.
    Copy HP Support Pack to Core Server
  3. Now connect to the Core Server and use the cmd.exe to navigate to the folder with the HP Support Pack
    Hyper-V Core Server HP Support Pack
  4. Run the “hpsum.exe” to start the HP Smart Update Manager
    hpsum.exe
  5. When the HP Smart Update Manager is started you can use it like on a Full Server installation of Windows Server 2008
    HP Smart Update Manager on Hyper-V Core ServerHP Smart Update Manager on Hyper-V Core ServerHP Smart Update Manager on Hyper-V Core Server

You could also try to run the HP Smart Update Manager on another machine and use the remote connection feature.