A
A
Alexander F2019-11-17 22:36:34
PowerShell
Alexander F, 2019-11-17 22:36:34

How to run commands sequentially in powershell?

There is a task.
Find files by mask, delete them and then write certain text to the "log" file.
It is necessary to make it on PowerShell
Separate commands found. How to make them run sequentially, i.e. if files are removed from the directory, then the Add-Content cmdlet writes certain text to the file, if the files are not found and are not deleted, then nothing is written?
In Bash, everything seems to be easier. How to do it in PowerShell?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2019-11-17
@lex63

powershell is verbose but mimics some variables

remove-item -path 'not existing.txt' -erroraction silentlycontinue; echo $?
False

new-item -path 'dummy.txt'
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       11/17/2019   8:24 PM              0 dummy.txt
remove-item -path 'dummy.txt' -erroraction silentlycontinue; echo $?
True

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question