Tag: command line

az next after az login

Az Next – AI-powered interactive assistant Azure CLI

As you know, the Azure CLI already AI-build in with the az find command, and you might have seen a great feature like AI-powered PowerShell module called Az Predictor Module (Azure PowerShell Predictions), which does what the name says, predict PowerShell commands. Now with az next, the team also brought a similar feature to the Azure CLI. The team’s goal with az next is to guide users through their scenarios or sequence of jobs-to-be-done in tool, so that they could remain focused and avoid unnecessary external documentation searches.

Az next adopts our latest design guidelines and should help making the Azure CLI more approachable for all users, including beginners.

There are two scenarios in which are currently supported. The first one is a simple walkthrough for the next commands as soon as you execute az next. After that, the Azure CLI will return set of command options, which are highly likely to come after your last command. This is super helpful if you are running a sequence of commands, the Azure CLI will provide you with predictive recommendations.

Here for example, the commands after I ran az login and logged in into my Azure environment, followed by az next.

az next after az login
az next after az login

The second one is the end-to-end scenario walkthrough with the aim to help you achieve a specific scenario in mind. In these case the options show up in form of a summary instead of an explicit command, and the tool will guide you through individual command completion.

az next after creating a resource group
az next after creating a resource group

Getting started with az next

To get started with az next, you can simply start using the preview by downloading the latest Azure CLI. You can log issues or feature requests in our GitHub repo:  GitHub – Azure/azure-cli: Azure Command-Line Interface 

Configure az next

The first time you run az next, you will be prompted to install the Azure CLI extension.

Install Az next
Install Az next

If your Azure CLI doesn’t automatically ask to install the extension. you can run the following command:

az extension add -n next

Now you can configure az next, to switch between the different modes and experiences.

Set a non-interactive experience:

az config set next.execute_in_prompt = False

Set the options to be more elaborated with parameters

az config set next.show_arugments = True

For additional customization

az next –-help

Learn more

To learn more, check out the full announcement blog for the az next command here on Tech Community.

If you want to learn more about the Az Predictor Module and PowerShell Predictive IntelliSense, check out my blog posts:



Get System Uptime with PowerShell

Get System Uptime with PowerShell

Sometimes you want to know how long your system is running. There are multiple ways to get the uptime of your system using the GUI or command line. PowerShell also offers a simple way to get the system uptime. If you are running PowerShell 6 or PowerShell 7 you can get the uptime with this simple cmdlet, which works on Windows, Linux, and macOS.

To get the system uptime on Windows, Linux, or macOS using PowerShell, you can use the Get-Uptime cmdlet.

Get-Uptime

Here how that looks on Ubuntu:

Get System Uptime on Linux using PowerShell

You can also use the “-Since” parameter to return a DateTime object representing the last time that the operating system was booted.

Get-Uptime PowerShell cmdlet with -since parameter

If you are running Windows PowerShell 5 or older, you can use the CIM Instance method and the Win32_OperatingSystem class. The Win32_OperatingSystem class has a LastBootupTime property which shows the time when the computer was rebooted.

Get-CimInstance -ClassName Win32_OperatingSystem | Select LastBootUpTime

I hope that quick PowerShell post gives you an overview of how you can get the system uptime on Windows, Linux, and macOS using PowerShell. If you have any questions feel free to leave a comment. If you want to know more about how you can install and update to PowerShell 7, check out my blog post, you can also learn what is new in PowerShell 7 right here.

You can also learn about PowerShell remoting between Windows, Linux, and macOS using PowerShell remoting over SSH.



Add Sleep Wait Pause in a PowerShell Script

How to Add Sleep/Wait/Pause in a PowerShell Script

Many of you know the “timeout” command we used when we created Windows Batch scripts. This pauses/waits/sleeps the script for a specific amount of time. In PowerShell, we can use the Start-Sleep cmdlet to suspend/pause/sleep/wait the activity in a script or session for the specified period of time. You can use it for many tasks, such as waiting for an operation to be completed or pausing before repeating an operation.

To sleep a PowerShell script for 5 seconds, you can run the following command

Start-Sleep -Seconds 5

You can also use the -milliseconds parameter to specify how long the resource sleeps in milliseconds.

Start-Sleep -Milliseconds 25

There are also aliases for the parameter such as -s and -ms if you don’t want to type out the full name. If you want to learn more about the Start-Sleep cmdlet, check out Microsoft Docs.

Another option is to use the Read-Host cmdlet. This is waiting until the user provides any input before the script continues and with that allows you to easily pause a PowerShell script until a key press, for example:

Read-Host -Prompt "Press any key to continue..."

Usually this is used to get some input from an user, which can be reused like:

$InputFromUser = Read-Host -Prompt "Get me some input..."

To learn more about what you can do with the Read-Host cmdlet, check out Microsoft Docs.

And I think many of you know, needless to say, that if you can avoid waits in a script, that’s a good thing. 😉

I hope that quick PowerShell post gives you an overview of how to add a sleep/wait/pause in a PowerShell Script. If you have any questions, feel free to leave a comment. If you want to know more about how you can install and update to PowerShell 7, check out my blog post, you can also learn what is new in PowerShell 7 right here.

You can also learn about PowerShell remoting between Windows, Linux, and macOS using PowerShell remoting over SSH.



Empty Windows recycle bin with PowerShell

Empty Windows recycle bin with PowerShell

Windows has the concept of the recycle bin, from which you can restore files you have deleted. You might want to clear the Windows recycle bin from time to time, to remove unnecessary files and free up space. You can do that using the Windows user interface, or you can empty the Windows recycle bin using PowerShell. The Clear-RecycleBin is a simple PowerShell cmdlet, which removes the file from the Windows recycle bin.

Clear-RecycleBin

You can also use the -force parameter if you don’t want the prompt to confirm.

Clear-RecycleBin -Force

I hope that quick PowerShell post, helps you to empty the Windows recycle bin using PowerShell, if you have any questions feel free to leave a comment. If you want to know more about how you can install and update to PowerShell 7, check out my blog post, you can also learn what is new in PowerShell 7 right here.



Use WinGet to install Microsoft Store Apps and Applications

Install Apps from the Microsoft Store using WinGet

Back at Build 2020, Microsoft showed a new package manager for Windows called WinGet (Currently in Public Preview). The winget command-line tool enables IT Pros and developers to discover, install, upgrade, remove, and configure applications on Windows 10 computers. This tool is the client interface to the Windows Package Manager service. One of the latest experimental features added to WinGet is the capability to also install apps from the Microsoft Store.

WinGet integrated perfectly into Windows 10, you can use it with the existing command line, PowerShell or the new Microsoft Terminal. If you want to learn more about WinGet, check out the official Microsoft Docs.

Enable the Microsoft Store apps experimental feature in WinGet

Microsoft Store App support in WinGet is currently implemented as an experimental feature. It supports a curated list of utility apps from the Microsoft Store.

Screenshot Winget features
winget features

To enable Enable the Microsoft Store experimental feature in WinGet, open the WinGet settings by typing:

winget settings

Now add the following part to the settings file:

"experimentalFeatures": {
       "experimentalMSStore": true
   },
winget settings
winget settings

Now you will also get apps from the Microsoft Store on Windows 10. You can verify the sources with the following command:

winget source list
Use WinGet to install Microsoft Store Apps and Applications
Use WinGet to install Microsoft Store Apps and Applications

And you can start installing apps from the Microsoft Store using WinGet. Don’t worry if you can’t find some of the apps in the Microsoft Store by using WinGet, since it is in preview only a small set of applications form the store are enabled to be installed by WinGet.

Conclusion

I hope this blog post helps you to enable the experimental feature in WinGet, which allows you to install apps from the Microsoft Store on Windows 10. If you have any questions, feel free to leave a comment. And if you want to learn more about WinGet, check out Microsoft Docs, where you can also learn how to build your own packages.



Windows File Recovery Tool WinFR

Recover Files on Windows using the Windows File Recovery Tool

Did you accidentally delete an important file, wiping a hard drive or partition, or need to restore corrupted files and data? We all have been there, with the newly released Microsoft Windows File Recovery tool you can recover and restore files on Windows. In this blog post, I am going to show you how you can recover and restore files on Windows using the Windows File Recovery tool. You can also use this tool to recover files from external drives and SD cards.

Accidentally deleted an important file? Wiped clean your hard drive? Unsure of what to do with corrupted data? Windows File Recovery can help recover your personal data.

For photos, documents, videos and more, Windows File Recovery supports many file types to help ensure that your data is not permanently lost.

Recovering from a camera or SD card? Try Signature mode, which expands beyond NTFS recovery and caters to your storage device needs. Let this app be your first choice for helping to find what you need from your hard drive, SSD (*limited by TRIM), USB drive, or memory cards.

I also want to make clear that this is no replacement for a backup, like Windows File History, Azure Backup, or products from third-party vendors. This tool is more of an emergency utility, you can restore files that were not backed up.

Requirements

To use the Windows File Recovery Tool, you have a couple of requirements.

  • You will need to run Windows 10, version 2004 (Build 19041), or later.
  • You can download the Windows File Recovery Tool from the Microsoft Store.
  • The source and destination drives must be different. If you don’t have a second drive on your computer, you can use a USB drive as a target for the restore. If you are storing form an SD card or external drive, you can use the internal system drive (often the C: drive) as a target.
  • The tool supports different file systems such as NTFS, ReFS, FAT, and exFAT. If you are restoring files from a non-NTFS file system, you will need to run the commands in signature mode using the /x parameter.


How to Change the Windows Terminal Default Shell Profile

How to Change the Windows Terminal Default Shell Profile

The Windows Terminal is now generally available as version 1.0. I already shared a blog post on how to customize the Windows Terminal and shared my personal settings.json file with a lot of different examples, like the integration of PowerShell Remoting, SSH Remoting, changing the background image and much more. One question I got is, how to change the Windows Terminal default shell or default profile from PowerShell to the Windows Subsystem for Linux (WSL) or the command line (cmd).

By default, the Windows Terminal takes PowerShell 7 (if it is installed) as the primary shell when you open the Windows Terminal. However, if you want to change that you can simply configure the default shell in Windows Terminal, in the settings.json file. On the top, you can find the “defaultProfile” setting with a GUID

{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
....
}

The GUID is the GUID of your profile. For example, if you want to change it to cmd, you can use the following GUID “0caa0dad-35be-5f56-a8ff-afceeeaa6101”.

Windows Terminal Default Profile - Default Shell

Windows Terminal settings.json

I hope this blog post gives you a look on how to switch the default shell in Windows Terminal. I recommend that you check out my other blog post where I share even more details on how to customize the Windows Terminal. You can also read the full announcement blog for the version 1.0 here or check out the documentation on Microsoft Docs.

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



Cascadia Code in Windows Terminal

Change the Windows Terminal Theme from Light to Dark

This is again a very small post on the Windows Terminal, like how to open the Windows Terminal from the command prompt or run and how to change the Windows Terminal background image. This time I got asked about how you switch the Windows Terminal Theme from light to dark. Well, the answer is pretty simple. The theme of the Windows Terminal is defined by the Windows 10 color theme. So to change the Windows Terminal theme from light to dark, you simply need to change the default app mode to dark or switch completely switch to dark in the Windows 10 personalization settings. Not like other Windows 10 apps, after you have switch the color mode, you will need to close and reopen the Windows Terminal to see the change.

The Windows Terminal is currently in preview and lets you run shells like the classic command-line, PowerShell or WSL and WSL 2. If you want to know how to install the Windows Terminal or how to customize the Windows Terminal, check out my blog post.

Change to Windows Terminal Dark Theme

Here is how you change it to the dark theme.

  1. Open Windows 10 Settings
  2. Go to Personalization
  3. Click on Colors
  4. Choose your color and select “Dark

Windows Terminal Dark Theme

Windows Terminal Dark Theme

 

Activate Light Theme

Here is how you change it to the light theme.

  1. Open Windows 10 Settings
  2. Go to Personalization
  3. Click on Colors
  4. Choose your color and select “Light

Windows Terminal Light Theme

Windows Terminal Light Theme

You can find more tips on how to customize the Windows Terminal on my blog. I hope this is a quick help, also check out my blog post about the new font called Cascadia Code. If you have any questions, please let me know in the comment.



Cascadia Code in Windows Terminal

New Microsoft Code and Terminal Font Cascadia Code

Cascadia Code is the latest monospaced font shipped from Microsoft focusing on delivering an excellent font for command-line experiences and code editors like Visual Studio Code. The Cascadia Code font was first announced at the Microsoft Build conference in May 2019. And yesterday, Microsoft just released Cascadia Code version 1909.16 and it is available publicly on GitHub. Cascadia Code makes an excellent font for the Windows Terminal, and you can download it today.

It is the latest monospaced font shipped from Microsoft and provides a fresh experience for command line experiences and code editors. Cascadia Code was developed hand-in-hand with the new Windows Terminal application. This font is most recommended to be used with terminal applications and text editors such as Visual Studio and Visual Studio Code.

I took some time to install Cascadia Code font on my Surface Book 2 and it works great with application like Visual Studio Code and the Windows Terminal running PowerShell. To start using it, simply download the font, install it, and configure the application to use is. In the Windows Terminal app, open the settings.json file and change the font in the specific terminal profile.

VS Code Cascadia Code setting for Windows Terminal

VS Code Cascadia Code setting for Windows Terminal

  "profiles" : 
    [
        {
            "acrylicOpacity" : 0.5,
            "closeOnExit" : true,
            "colorScheme" : "VibrantInk",
            "commandline" : "C:\\Program Files\\PowerShell\\6\\pwsh.exe",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Cascadia Code",
            "fontSize" : 12,
            "guid" : "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
            "historySize" : 9001,
            "icon" : "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png",
            "name" : "PowerShell Core",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true,
            "backgroundImage": "C:/Users/thoma/OneDrive/Pictures/Me/Thomas Maurer Logos 2016/WindowsTerminal/Black Cloud Robot.png",
            "tabTitle": "PowerShell Core "
        },

If you want to know more about customizing the Windows Terminal, check out my blog post. You can find more tips on how to customize the Windows Terminal on my blog. If you are optimizing and customizing your code editor experience, you should also have a look at my favorite themes for Visual Studio Code.

The font is open source and licensed under the SIL Open Font license on GitHub, so it is easy to contribute. Have you tried the Cascadia Code font, and what do you think about the new coding font? Do you like it? And if you have any questions, please let me know in the comments.

If you are looking for some other cool Microsoft coding projects, have a look at Azure Cloud Shell and PowerShell 7.



Download the new Windows Terminal Preview

How to open Windows Terminal from Command Prompt or Run

This is a really short blog post and more of a reminder than anything else. You might have seen the new Windows Terminal for Windows 10 was just released in the Windows Store as a preview. However, in the last couple of updates to the Windows Terminal app, it got to a state which already makes it my default terminal. The Windows Terminal allows you to run Windows PowerShell, PowerShell Core and even Bash using the Windows Subsystem for Linux (WSL). Especially the integration of the Azure Cloud Shell is a great plus for me. In this blog post, I am just going to show you how you can open the Windows Terminal from command prompt or Run (WIN + R).

To open Windows Terminal from the command line (cmd) or in Windows Run (WIN +R) type:

wt

Open Windows Terminal start wt

Open Windows Terminal start wt

 

If you want to know more about the Azure Cloud Shell integration, read the blog of Pierre Roman (Microsoft Cloud Advocate) on the ITOpsTalk blog.