Create Folder + current date issue

This post was originally published on this site

Hi All

 

I’m trying to check and create a folder to collect LOGs, unfortunatelly without success

the script should, first check the folder and the path, then create a folder if the checkdir return”False”

 

  1. the folder should be HardeningESXi-Logs+date
  2. the folder for SessionsLoGFiles should be SessionsLoGFiles+date

 

#Connect to vcenter

$vcenter = Read-Host “vCenter name:”

$user = Read-Host “User:”

$password = Read-Host “Password:”

 

Write-Host -f green “Connecting to vCenter Server…”

Connect-VIServer -Server $vcenter -User $user -Password $password

 

$prefixe=$(get-date -format ‘yyyy.MM.dd_HH.mm.ss_’)

 

#information where log files sessions are uploaded

$SessionsLoGFiles=”.HardeningESXi”+ $prefixe+ “SessionsLoGFiles.log”

 

#Create folder for logs output

$checkdir = Test-Path “.HardeningESXiHardeningESXi-Logs” -PathType Container

if ($checkdir -eq “*True*”){}

else {New-Item .HardeningESXiHardeningESXi-Logs -ItemType directory}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.