# Get today's date in YYYYMMDD format and time in HHmmss format $Today = Get-Date -Format 'yyyyMMdd' $Now = Get-Date -Format 'HHmmss' # Create the directory if it doesn't exist if ( !( Test-Path "\\Server\Logs\$Today" -PathType Container ) ) { New-Item -Path "\\Server\Logs" -Name $Today -ItemType "directory" } # Log current computer access "$Env:ComputerName,$Today,$Now\n" | Out-File -FilePath "\\Server\Logs\$Today\$Env:UserName.log" -Encoding ASCII