Solved

Powershell script to delete VHD files on Windows LAN clients

Posted on 2011-03-18
4
909 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now