Удаление службы windows с помощью командной строки или power shell

How to Find a File or Folder’s Full Path

To remove files or folders from your Windows PC, you’ll need the item’s full path. If you know how to get file or folder paths, skip to the relevant section below. If you aren’t sure how to copy a file or folder’s full path, we’ll show you how.

First, open a File Explorer window and locate the file or folder whose path you want to find. Then, hold down the Shift key on your keyboard, right-click your file or folder, and choose “Copy as Path.”

Удаление службы windows с помощью командной строки или power shell

You’ve successfully copied the selected item’s path to your clipboard. You can now paste this path (using Ctrl+V) wherever required within the PowerShell window.

Quick Links

Key Takeaways

  • To delete a file or folder, use the “Remove-Item PATH” cmdlet in PowerShell. In this command, replace “PATH” with the full path to the file or folder you want to remove.
  • To delete all files in a folder but keep the folder, use the “Remove-Item PATH\*.*” command, where “PATH” is the full path to the folder.
  • To remove all files from a folder and its subfolders, use the “Remove-Item PATH -Recurse -Include *.*” command, replacing “PATH” with the full path to your parent folder.

PowerShell offers a straightforward way to delete files and folders on your Windows 11 or Windows 10 PC. You can remove folders, all files inside a folder, specific files from the specified directory, and so on using just a few commands. Here’s how to do that.

In this post, I’ll demonstrate using the sc delete Windows command and the Remove-Service PowerShell command to delete a Windows Service.

Step 1. Find the Service Name

Open Windows Services, find the service name, right click and select properties.

Copy the service name.

Удаление службы windows с помощью командной строки или power shell

Step 2. Run the sc delete command

Удаление службы windows с помощью командной строки или power shell

Next, run the below command. Replace “servicename” with the service name from Step 1.

sc delete servicename

You should get DeleteService SUCCESS message.

Удаление службы windows с помощью командной строки или power shell

You might need to reboot the computer for the service to be completely removed.

Удаление службы windows с помощью командной строки или power shell

That completes the steps for deleting a windows service using the sc command.

How to Delete a Windows Service Using PowerShell

Requirements: You will need to be running at least PowerShell version 6 for this command to work. Refer to the updating PowerShell guide for steps on upgrading PowerShell to the latest version.

Step 1. You will need the service name

Open Windows services and get the service name. If you need to see screenshots see the Windows command line example.

Step 2. Run Remote-Service PowerShell command.

Remove-Service -Name servicename
Удаление службы windows с помощью командной строки или power shell

Note: I’m not sure why but the PowerShell command removed the service without requiring a reboot. The sc delete command required a reboot. It might depend on the service but just be aware you might need to reboot.

If you liked this post, you might also want to check out:

We’ve all been there – you’re trying to uninstall a piece of software, but it just doesn’t seem to be as straightforward as you’d like. Perhaps the traditional uninstall process is proving to be a hassle, or maybe the software doesn’t seem to want to leave your system, no matter how hard you try.

That’s where PowerShell comes in.

In this article, we’ll show you three effective methods that leverage the power of PowerShell to manage and uninstall software packages with ease:

  • WMI Method
  • Package Provider
  • Uninstallation String

Let’s get started!

Uninstalling Software with the WMI Method

One of its key components is the Win32_Product class that embodies products installed by Windows Installer.

Get-WmiObject -Class Win32_Product | Select-Object -Property Name

After a few seconds, the command will come up with a list of most applications installed on your PC.

WMI Method PowerShell

2. From this list, identify the exact name of the application you wish to uninstall. It’s crucial to match the name exactly as it appears in the PowerShell output.

:/>  batch file - how to combine two variables in cmd.exe script - Stack Overflow

3. To locate your application, modify your command as shown below, replacing “PowerShell Test Application” with the name of your application:

Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "PowerShell Test Application"}
WMI command PowerShell
$MyApp = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "PowerShell Test Application"}
$MyApp.Uninstall()

While effective, the WMI Method has its limitations:

  • It is resource consuming.
  • There are cases where the WMI Repository is corrupted.
  • Not all applications can be uninstalled by the WMI Method.

In case you’re unable to find your specific application using the WMI Method, the Get-Package cmdlet comes to the rescue, which leads us to the second method.

Uninstalling Software with the Uninstall String

The Uninstallation String method is ideal for custom packages. If a package appears in the Control Panel’s Add & Remove Programs, it creates an entry in the registry.

– For 64bit packages:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

– For 32bit packages:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

To uninstall a package using the Uninstallation String, locate the specific package entry and identify its uninstall string.

For example, if we look at the UXP WebView Support package, we can see that it has a custom uninstall string.

uninstall string for software uninstalling

Conclusion

We’ve journeyed through the comprehensive landscape of uninstalling software packages using PowerShell, navigating through three dynamic methods – the WMI Method, Package Provider, and Uninstallation String. Each of these approaches is designed to give you control, flexibility, and precision when managing software on your system.

Whether you’re handling conventional applications or unique, custom packages, these PowerShell methods offer powerful solutions for your uninstallation needs. The key is understanding each method’s advantages and limitations, and strategically applying them based on your specific circumstances.

We hope this guide helps you harness the potential of PowerShell Package Management, enabling you to manage your software environment with confidence and efficiency. Continue exploring, and keep enhancing your software management skills. Remember, in the realm of PowerShell, you’re only limited by what you don’t know. Happy uninstalling!

See author's page

Alex Marin

Application Packaging and SCCM Deployments specialist, solutions finder, Technical Writer at Advanced Installer.

Do you want to delete files in PowerShell? In this tutorial, I will show you various methods to delete files using PowerShell.

1. Using the Remove-Item Cmdlet

The primary command for deleting files in PowerShell is Remove-Item. This cmdlet is used to delete various types of items, including files, directories, registry keys, and more.

Here’s a basic example of how to delete a single file:

Remove-Item -Path "C:\MyFolder\file.txt"

This command will delete the file specified in the path. If the file does not exist, PowerShell will throw an error.

Delete Multiple Files in PowerShell

To delete multiple files in PowerShell, you can use wildcards (*) to match multiple files. For instance, to delete all .txt files in a directory:

Here is the cmdlet.

Remove-Item -Path "C:\MyFolder\*.txt"

Here you can see below I have in the folder there are multiple .txt files.

Delete a File in PowerShell

Now, after I ran the above PowerShell script using VS code, it deleted all the .txt files from the folder; check the screenshot below:

Delete Multiple Files in PowerShell

Delete Files with Confirmation in PowerShell

If you want to avoid accidental deletions of files, you can add the -Confirm parameter, which will prompt you before deleting each file:

Remove-Item -Path "C:\MyFolder\file.txt" -Confirm

Force Delete Read-Only Files in PowerShell

Sometimes, you may encounter read-only files that cannot be deleted without additional permissions. To delete such files, use the -Force parameter in PowerShell:

Remove-Item -Path "C:\MyFolder\readonlyfile.txt" -Force

Delete Files Recursively in PowerShell

To delete files and subfolders within a directory recursively, you can use the -Recurse parameter. This will delete both the files and subfolders within the specified path:

Remove-Item -Path "C:\MyFolder\directory" -Recurse

2. Using Get-ChildItem with Remove-Item

Deleting Files Based on a Condition

Get-ChildItem -Path "C:\path\to\your\directory" -File | Where-Object { $_.Length -gt 1MB } | Remove-Item

Deleting Files Older Than a Certain Date

To delete files that are older than 30 days, you could use the below PowerShell script:

$Date = (Get-Date).AddDays(-30)
Get-ChildItem -Path "C:\path\to\your\directory" -File | Where-Object { $_.LastWriteTime -lt $Date } | Remove-Item

3. Using the .NET Method

PowerShell also allows you to tap into .NET Framework’s capabilities to delete files. This method offers more advanced options and can be useful in certain scenarios.

:/>  ES Проводник для Windows 10 скачать бесплатно русская версия

Here’s an example of using the .NET method to delete a file:

[System.IO.File]::Delete("C:\MyFolder\file.txt")

This line of code directly calls the Delete method from the System.IO.File class to remove the specified file.

Error Handling When Deleting Files Using PowerShell

Here’s an example of error handling in a file deletion script in PowerShell:

try {
    Remove-Item -Path "C:\MyFolder\file.txt" -ErrorAction Stop
} catch {
    Write-Host "An error occurred: $_"
} finally {
    Write-Host "Operation completed."
}

Conclusion

Deleting files using PowerShell is a straightforward process that can be performed using various methods, including the Remove-Item cmdlet, combining Get-ChildItem with Remove-Item, or using the .NET Framework.

In this PowerShell tutorial, I have explained how to delete a file in PowerShell using various methods.

You may also like:


u/CMDR_Kantaris avatar


Format your disk drive and reinstall Windows




Wow such a nice solution.




u/ItsNippy7 avatar


So is the only way to remove this a full system reset ?




u/AppIdentityGuy avatar





u/purplemonkeymad avatar


If you do re-install make sure to use a different computer to create your install disk, as it’s possible for install disks created on an infected system to install infected copies of windows.




u/flappers87 avatar


It’s the safest way with any virus.

Anti virus programs can only do so much, and are always playing catchup with viruses. Best thing to do is a complete, deep format of the drive and start again. Don’t backup anything, as you don’t know where this virus has got it’s hands in.

If I had a virus like you’ve got, I’d burn the machine with fire, as it should be put out of it’s misery.




u/CMDR_Kantaris avatar


It is the easiest, quickest, and only way to be 100% positive it has been removed.







Fly up and nuke it from orbit.

It’s the only way to be sure.




There’s no such thing as powershell virus. Viruses can use powershell to “do their needful”, because it’s just a tool.

Either hire someone who knows what they are doing to cleanse this system (costs a lot, high chance to hire a scammer) or reinstall.




This isn’t a PowerShell question. It’s a Windows question. Virus removal can be challenging. What’s your expertise level?

Basically you need to find out what’s triggering PowerShell scripts. It’s probably a scheduled task or a service or program that starts at boot / logon. Then you need to understand what the PowerShell scripts did and any other impact the virus made on your system. Then you delete the virus files and any scripts it was running, or neuter them by changing them to text files (in case you want to remember later what exactly they were doing).

A pre-installation environment is your friend. But you need to know what to delete first.


:/>  На удаленном принтере ошибки 0x0000011b из-за чего возникают? Изучать как в Windows 10, 11 устранить ошибку



u/Filwegg avatar





u/BroadRecy avatar


You could try open the task manager and go to the details tab. There you add the command line column. Now you look up your power shell instance(s) and see what initiated those. With that information you can maybe find out what virus is on your system and use that specific information to find out more.




This is what I believe you should do to remain safe.

  1. Disconnect your PC from the network.

    1. Use the ‘Details’ tab and also add the column named ‘Command Line’.

  2. Locate powershell processes and review the ‘Command Line’ column to locate what file is being executed.

  3. Based on this information you now have the location of the script and its name. You could use a tool like AutoRuns to locate how it is being executed and perhaps remove the execution of it from your system.

Note this simply removes this file’s execution, this does NOT resolve the issue for how it got on there or what actions it has already taken you your computer. This would require much more investigation. But with the script in hand you could also perhaps perform some analysis of this file and see what it does which may help.

To be 100% though a reimage of the computer would be best.




How to Delete a Specific Folder Using PowerShell

You can use PowerShell’s “Remove-Item” cmdlet to remove any directory from your PC.

Deleting a folder removes all the subfolders and files inside it.

Remove-Item PATH

As an example, to delete a directory named “Old Files” from your desktop, you’d run:

Remove-Item "C:\Users\username\Desktop\Old Files"
The 'Remove-Item' cmdlet to delete a folder in a PowerShell window.

How to Delete a Specific File Using PowerShell

To remove a specific file from your PC, use PowerShell’s “Remove-Item” cmdlet.

Remove-Item PATH

As an example, to delete a file named “Old-List.txt” on your desktop, you’d run:

Remove-Item "C:\Users\username\Desktop\Old-List.txt"
The 'Remove-Item' cmdlet to delete a file in a PowerShell window.
Remove-Item "C:\Users\username\Desktop\Old-List.txt" -Confirm

How to Delete Files With Wildcards

PowerShell offers wildcards, allowing you to delete various kinds of files by just specifying those file types in your command. In all the examples below, replace “PATH” with the full path to your folder.

Remove-Item PATH -Include *.jpg
Remove-Item PATH -Exclude *.pdf
Get-ChildItem -Recurse PATH | where { $_.PSISContainer -and @( $_ | Get-ChildItem ).Count -eq 0 } | Remove-Item

And you’re set.


Now that you know how to delete items with PowerShell, you won’t be stuck when File Explorer refuses to work. PowerShell offers more ways than File Explorer to help you remove content, like the ability to only remove specific files with a single command.

How to Delete All Files From a Folder and Its Subfolders

If you’re looking to remove all files from a folder and its subfolders, add the “Recurse” and “Include” parameters to the “Remove-Item” cmdlet.

Remove-Item PATH -Recurse -Include *.*

Here, the “Recurse” parameter ensures the subfolders’ files are deleted as well. The “Include” parameter ensures files with any name and extension are removed.

As an example, to remove all files from the “Downloads” folder and its subfolders on the desktop, run:

Remove-Item "C:\Users\username\Desktop\Downloads" -Recurse -Include *.*
The 'Remove-Item' cmdlet to recursively delete items on a PowerShell window.

How to Delete All Files in a Folder But Keep the Folder

Remove-Item PATH\*.*

For example, to delete all files from a folder named “Your Files” from the desktop, run:

Remove-Item "C:\Users\username\Desktop\Your Files\*.*"
The 'Remove-Item' cmdlet to delete all files inside a folder on a PowerShell window.

In this command, the first asterisk selects files with any name, and the second asterisk chooses files with any extension. This translates to selecting all the files in the specified folder.

Оставьте комментарий