VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot

Create Folder + current date issue

Hi All

I'm trying to check and create a folder to collect LOGs, unfortunatelly without success Smiley Sad

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 ".\HardeningESXi\HardeningESXi-Logs" -PathType Container

if ($checkdir -eq "*True*"){}

else {New-Item .\HardeningESXi\HardeningESXi-Logs -ItemType directory}

1 Reply
LucD
Leadership
Leadership

You should compare with a Boolean value.

if ($checkdir -eq $true){}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference