VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot
Jump to solution

Create Folder in this format | FolderName date Time

I'm trying to create folder to collect LOGs and output session, as these logs will be used later for archive reference and to trace change.

my issue is that I woulde like the folder to have this foirmat :  folder name 2020/09/23 14:56:00

I got the below error

New-Item : The given path's format is not supported.

At line:5 char:7

+ else {New-Item -itemType Directory -Path E:\Test_Folder -Name ("LOGS  ...

+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-Item], NotSupportedException

    + FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.NewItemCommand

----------------------------------- Script ---------------------------------

$folderName = Get-Date -Format 'yyyy.MM.dd HH:mm:ss'

$checkdir = Test-Path "E:\Test_Folder\LOGS + $FolderName" -PathType Container

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

else {New-Item -itemType Directory -Path E:\Test_Folder -Name ("LOGS " + $FolderName)}

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Or simply :smileygrin:

$folderName = Get-Date -Format 'yyyy.MM.dd HH.mm.ss'


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

View solution in original post

11 Replies
daphnissov
Immortal
Immortal
Jump to solution

Wrong subforum. Move to PowerCLI.

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee
Jump to solution

Moderator: Thread moved to the PowerCLI area, although from what I can tell your issues are specific to PowerShell itself rather than any PowerCLI cmdlets.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
SCharchouf
Hot Shot
Hot Shot
Jump to solution

I agree, hope that can someone assist me :smileyblush:

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The ':' character is invalid in a filename on a Windows NTFS filesystem.


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

SCharchouf
Hot Shot
Hot Shot
Jump to solution

Do you have any idea how I can solve this?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Rewrite Windows?


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

LucD
Leadership
Leadership
Jump to solution

Seriously though, you can't use an invalid character if that is defined by the OS.
Use another character instead of ':'


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

daphnissov
Immortal
Immortal
Jump to solution

Easy fix in your first line:

$folderName = Get-Date -Format 'yyyy.MM.dd HH:mm:ss' | ForEach-Object { $_ -replace ":", "." }

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Or simply :smileygrin:

$folderName = Get-Date -Format 'yyyy.MM.dd HH.mm.ss'


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

daphnissov
Immortal
Immortal
Jump to solution

How stupid of me, of course. Please ignore my reply and use Luc's.

SCharchouf
Hot Shot
Hot Shot
Jump to solution

it's Ok both oif you helped me Smiley Happy Smiley Wink:smileygrin:

Reply
0 Kudos