Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

delete file on powershell script

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

Is Your AD Toolbox Looking More Like a Toybox?

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

722 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