Automation

 View Only
  • 1.  Create Folder + current date issue

    Posted Sep 21, 2020 07:08 AM

    Hi All

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

    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}



  • 2.  RE: Create Folder + current date issue

    Posted Sep 21, 2020 07:46 AM

    You should compare with a Boolean value.

    if ($checkdir -eq $true){}