Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

delete file on powershell script

Posted on 2012-03-12
3
Medium Priority
?
445 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline

972 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