Эквивалент power shell

What is the PowerShell equivalent to DISM‘s /Cleanup-Image in this command:

DISM /Image:%mounted_image% /Cleanup-Image /StartComponentCleanup /Resetbase /ScratchDir:%scratch_dir%

Within Use DISM in Windows PowerShell, there is no corresponding PowerShell cmdlet, so is this Repair-WindowsImage command the equivalent to the above command?

Repair-WindowsImage -Path $mounted_image -RestoreHealth -ScratchDirectory $scratch_dir

JW0914's user avatar

7 gold badges31 silver badges50 bronze badges

wolfrevo's user avatar

The parameters of Dism commands are an almost 1:1 to the parameters of PowerShell’s Dism cmdlets, with the main difference being cmdlets use - instead of /, coupled with some additional paraemeters, such as -ScratchDirectory, being supported for Package Servicing.

The man page for the equivalent Dism cmdlets is Use DISM in Windows PowerShell, which links to cmdlet Repair-WindowsImage:

  • Repair-WindowsImage <-Online | -Path> is the equivalent of:
    Dism </Online | /Image:> /Cleanup-Image
    • Repair-WindowsImage cmdlet command:
      Repair-WindowsImage -Path $mounted_image -RestoreHealth -ScratchDirectory $scratch_dir

      is not the equivalent of /StartComponentCleanup:

      # There is no /ScratchDirectory parameter: Dism /Image:$mounted_image /Cleanup-Image /StartComponentCleanup /Resetbase

      Instead, it’s the equivalent of /RestoreHealth:

      Dism /Image:$mounted_image /Cleanup-Image /RestoreHealth

Correct Repair-WindowsImage command: (-ScratchDirectory not required)

Repair-WindowsImage -Path $mounted_image -StartComponentCleanup -ResetBase -ScratchDirectory $scratch_dir
  • If running against an online Windows image [%SystemDrive% | $env:SystemDrive], -Online is used in lieu of -Path, however one or the other must be specified:
    • -Online: services packages of an online [booted to] Windows image
      e.g. Dism /Online
    • -Path: services packages of an offline [non-booted to] Windows image
      e.g. Dism /Image:<path>

JW0914's user avatar

7 gold badges31 silver badges50 bronze badges

I’m not sure about the other switches, but
dism.exe /online /cleanup-image /restorehealth
works perfectly fine in powershell.

kevin freels's user avatar

For years, PowerShell Integrated Scripting Environment (ISE) has been the primary tool on Windows for scripting in . Even so, Microsoft has deprecated this feature and will no longer add more functionalities. Although Microsoft has stated that PowerShell ISE will remain in Windows for the time being, it is no longer supported in PowerShell version 6 and higher.

Given PowerShell ISE’s uncertain future, it’s worth exploring alternative development platforms.

As strange as it may sound, I never use PowerShell ISE when developing PowerShell code. Instead, I write the majority of my code in Notepad. While Notepad lacks features such as the terminal window and syntax highlighting, I like it because it is super lightweight and easy to read.

Of course, you can write PowerShell code in nearly any text editor, and there are plenty of editors that have far more features than Notepad. Editors like Notepad++, UltraEdit, and Sublime Text come to mind, but there are many others to choose from.

What Is Visual Studio Code?

For those seeking a PowerShell ISE-like development experience, the current go-to tool from Microsoft is Visual Studio Code (). Unlike Visual Studio, Visual Studio Code is free and doesn’t require a subscription. Better still, like PowerShell, Visual Studio Code offers cross-platform compatibility, available for on Windows, MacOS, and Linux, with a web version also provided by Microsoft.

Perhaps the most notable difference between Visual Studio Code and PowerShell ISE is that it is not limited to PowerShell. Visual Studio Code provides native support for JavaScript, Python, Java, Markdown, Typescript, C/C++, JSON, PowerShell, HTML / CSS C#, PHP, and YAML. Additionally, it has a huge number of supported extensions, with some pre-installed by default.

Setting Up Visual Studio Code

Although Visual Studio Code is powerful and feature-rich, setting it up for the first time might not be the most intuitive process. Upon launching Visual Studio Code, you will be prompted to select a theme. Once you have done that, click on the folder icon and then the “Add a Folder” link, as shown in Figure 1. When prompted, select the folder where you will store your PowerShell scripts, and then click Add. Your chosen folder will now be added to the console tree.

A screenshot shows the Add a Folder link during a Visual Studio Code setup process

To create a new file, hover over the folder you just added and then click on the “New File” icon. When prompted, enter a filename, including the PowerShell script extension. For example, I entered as the filename.

If your filename includes the .PS1 file extension, Visual Studio Code will recognize that you intend to write PowerShell code and automatically prompt you to install the PowerShell extensions, as shown in Figure 2.

A screenshot shows Visual Studio Code prompting user to install PowerShell extensions

Upon clicking the Install button, Visual Studio Code will install everything you need for writing PowerShell code. However, as you can see in Figure 3, the main window also gives you an option to install PowerShell 7 if desired. Although PowerShell 7 is indeed the latest version of PowerShell, it is designed to be cross-platform, and so therefore lacks some of the Windows-specific cmdlets.

A Screenshot shows Visual Studio Code giving user the option to install PowerShell 7

Syntax Highlighting and ISE Mode

Now that the PowerShell extension has been installed, there are two more things I would like to highlight about the editor. First, if you look back at Figure 3, you will notice that the main window is tabbed. Since this is the first time that I have used the editor with PowerShell, a Welcome tab was automatically created. Additionally, there is a separate tab for my Demo.ps1 file. In Figure 4, you can see that Visual Studio Code uses syntax highlighting for the code that I have written. There is also a Terminal window located at the bottom of the screen.

A screenshot demonstrates syntax highlighting in Visual Studio Code

Another feature of Visual Studio Code worth highlighting is its inclusion something called . If you return to the Welcome tab and scroll down, you will find an option to try ISE mode, shown in Figure 5.

A screenshot shows the option in Visual Studio Code to enable ISE mode

Enabling ISE mode transforms Visual Studio Code’s appearance to closely resemble that of PowerShell ISE. This mode even grants access to PowerShell ISE’s Command Explorer. You can see how ISE mode looks like in Figure 6.

A screenshot showing what ISE mode looks like in Visual Studio Code

As previously noted, there’s no pressing need for you to make the switch to Visual Studio Code. PowerShell ISE is not going away any time soon, and you can still opt for a text editor if you prefer. Nevertheless, Visual Studio Code offers extensive support for multiple languages, works across different platforms, and offers development features that surpass those found in PowerShell ISE.

About the Author(s)

Brien Posey

Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.

:/>  Команды для «Командной строки» в Windows 10