Solved

delete file on powershell script

Posted on 2012-03-12
3
435 Views
Last Modified: 2012-03-13
hello,

With this code, i try to delete files, these files exist but it doesn't work :
$FileExists = "C:\dba\install\ini\cluster_configurationfile.ini"
$FileExists2= "C:\dba\install\ini\node_configurationfile.ini"
If ($FileExists -eq $True) { remove-item $FileExists}
If ($FileExists2 -eq $True) { remove-item $FileExists2}

How can I resolve this problem?

Thanks

bibi
0
Comment
Question by:bibi92
  • 2
3 Comments
 
LVL 3

Expert Comment

by:WebF00L
ID: 37711347
try

"Remove-Item $FileExist2 -force"

// WebFooL Untangle Evangelist
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 37711349
Try this

$FileExists = Test-path "C:\dba\install\ini\cluster_configurationfile.ini"
$FileExists2= Test-path "C:\dba\install\ini\node_configurationfile.ini"
If ($FileExists) { get-item $FileExists | remove-item}
If ($FileExists2) { get-item $FileExists2 | remove-item }
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 37711380
What you were doing is just giving powershell a string. $FileExists does not give a value of TRUE or FALSE. You will need to verify that file does exist and not just give a string value. You can use test-path for this. To verify run
$FileExists = Test-path "C:\dba\install\ini\cluster_configurationfile.ini"

then type

$FileExists

it will return a value of TRUE or FALSE.

Then you use get-item and pass through the pipe line to remove item.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

20 Experts available now in Live!

Get 1:1 Help Now