PowerCLI

 View Only
  • 1.  Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 10:55 AM

    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)}



  • 2.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 01:43 PM

    Wrong subforum. Move to PowerCLI.



  • 3.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:15 PM

    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.



  • 4.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:29 PM

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



  • 5.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:35 PM

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



  • 6.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:38 PM

    Do you have any idea how I can solve this?



  • 7.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:40 PM

    Rewrite Windows?



  • 8.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:41 PM

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



  • 9.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:48 PM

    Easy fix in your first line:

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



  • 10.  RE: Create Folder in this format | FolderName date Time
    Best Answer

    Posted Sep 23, 2020 02:52 PM

    Or simply :smileygrin:

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



  • 11.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 02:55 PM

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



  • 12.  RE: Create Folder in this format | FolderName date Time

    Posted Sep 23, 2020 03:06 PM

    it's Ok both oif you helped me :smileyhappy: :smileywink::smileygrin: