Powershell If statement example

Posted on

Powershell if statement syntax:

   1: If (condition) {statement}

Example 1 – Checking file or directory existence and copying file if it is exists

   1: $iis ="C:\logs\test.log"
   2: $file = "\\netshare\destination.log"
   3: if(Test-Path $iis){ Copy-Item $iis $file -force}

  • Fran_sun

    Please help. How do I execute more than one Execute commands in the { ….} block? For example, rename and send-message. I tried the pipe in between the command which doesn’t work. I couldn’t findĀ it mentioned anywhere.