Solved

delete file on powershell script

Posted on 2012-03-12
3
437 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Synchronize a new Active Directory domain with an existing Office 365 tenant
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now