Solved

delete file on powershell script

Posted on 2012-03-12
3
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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