Solved

Powershell script to delete VHD files on Windows LAN clients

Posted on 2011-03-18
4
913 Views
Last Modified: 2012-05-11
Hi

I'd like to experiment with Powershell so here goes:

How would I execute a command on a server to remove VHD (Virtual Hard Disk) files from the F:\ drive on a Windows client called PC01?

Server is 2003 R2 and client is XP SP3

Thanks

Phil

0
Comment
Question by:philanderson888
  • 3
4 Comments
 
LVL 13

Accepted Solution

by:
soostibi earned 50 total points
ID: 35164543
Do you have PowerShell v2 installed and PowerShell remoting enabled?
If yes, you can do this

Invoke-Command -ComputerName PC01 -ScriptBlock {Get-ChildItem -Path f:\ -Recurse -Filter *.vhd | Remove-Item }

If not, then if admin share is accessible you can do this:

Get-ChildItem -Path \\PC01\f$ -Recurse -Filter *.vhd | Remove-Item
0
 

Author Comment

by:philanderson888
ID: 35175412
Hi

I have neither installed - I think I will try this from a Windows 7 virtual machine which I have installed on the network and see if I can make this happen.  Hopefully I will get back to you Mon or Tues at the latest as it's a work machine.

Regards

Phil
0
 

Author Comment

by:philanderson888
ID: 35209820
Hi

Thank you for this - it was simple and it worked fine from a 2003 R2 server with Powershell v1 installed.

Many thanks for your help.

Philip

0
 

Author Closing Comment

by:philanderson888
ID: 35209835
Thanks very much for your help - I may be back for more!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question