Powershell script to delete VHD files on Windows LAN clients

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

philanderson888Asked:
Who is Participating?
 
soostibiConnect With a Mentor Commented:
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
 
philanderson888Author Commented:
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
 
philanderson888Author Commented:
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
 
philanderson888Author Commented:
Thanks very much for your help - I may be back for more!
0
All Courses

From novice to tech pro — start learning today.