title: Powershell backup script creating directory
body: <p>I have this type of code in a backup script.</p>
  <pre><code>
  
  while($true){
  $time = Get-Date -Format HH:mm:ss
  $dateCheck = (Get-Date).AddDays(-0).ToString('dd-MM-yyyy')
  [int]$check = $check
  
  
  Get-ChildItem 'C:\fleet-integrator-installer-DHL2\work\matilda\14\done' -File |
  Sort-Object -Property CreationTime -Descending |
  Select-Object -First 1 |
  Copy-Item -Destination \\Ict_nas\dhl\$dateCheck -Force
  
  if($time -eq ('23:59:00')){
  $check = $check - $check
  }
  
  if($time -eq ('23:59:30') -and $check -eq 0){
  New-Item -ItemType &quot;directory&quot; -Path &quot;\\Ict_nas\dhl&quot; -Name $dateCheck | Out-Null
  $check++
  }
  
  if($time -eq ('00:00:00')){
  $fileCount = ( Get-ChildItem C:\fleet-integrator-installer-DHL2\work\matilda\14\done ).Count;
  $EmailFrom = &quot;...&quot;
  $EmailTo = &quot;...&quot;
  $Subject = &quot;Backup DHL Integrator -&gt; IT NAS&quot;
  $Body = &quot;The backup was succesful, $fileCount files are copied to the NAS&quot;
  $SMTPServer = &quot;smtp.gmail.com&quot;
  $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  $SMTPClient.EnableSsl = $true
  $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(&quot;&quot;, &quot;&quot;)
  $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
  Get-ChildItem -Path C:\fleet-integrator-installer-DHL2\work\matilda\14\done -Include *.* -File -Recurse | foreach { $_.Delete()}
  }
  
  
  
  
  }
  </code></pre>
  <p>It is creating automaticly an folder with the date of today on a NAS.</p>
  <p>When i run the code separate it is working fine but in the script it is just creating a file with the date of today...</p>
  <p>Anyone tips?</p>
  <p>Thanks</p>