Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Dec 2009
    Location
    Gillingham, Dorset, UK
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 11 Posts

    PowerShell Version 5.1

    Has anyone on here used a cmdlet which, I believe, came with PS version 5.1, named New-FileCatalog?

    I was trying it out, and discovered something odd, and I would like to ask any of you who have PS V5.1 if you would please try running the following script, to confirm that what I'm seeing isn't something to do with my setup.

    Code:
    Please copy and paste the following into a script file:
    ScriptFileName: AnythingYouWantToCallIt.ps1
    
    #requires -Version 5.1
    
    # Leave the next line commented out for the first run
    #[CmdletBinding()]
    
    param (
      $path = 'path'  # ENTER A PATH HERE. MAKE SURE THAT IT CONTAINS A MINIMUM OF 1 FILE
    )
    
    New-FileCatalog -Path $path -CatalogFilePath C:\Source.cat -CatalogVersion 2.0
    New-FileCatalog -Path $path -CatalogFilePath C:\Destination.cat -CatalogVersion 2.0
    
    'C:\Source.cat', 'C:\Destination.cat' | Remove-Item
    That's it. Now run the script, adding the -Verbose switch parameter, e.g. .\AnythingYouWantToCallIt.ps1 -Verbose

    Then, edit the script and uncomment the line containing "[CmdletBinding()]", save the file and run it once more with the -Verbose switch.

    On my system, it produces verbose messages, even though, as can be plainly seen, the script does not contain any 'Write-Verbose' commands.

    Thanks in advance
    Last edited by Cliff.H; 2017-08-09 at 13:35.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,081
    Thanks
    429
    Thanked 1,621 Times in 1,462 Posts
    Cliff,

    I ran it in the ISE and got this.

    Code:
    PS> #requires -Version 5.1
    
    # Leave the next line commented out for the first run
    #[CmdletBinding()]
    
    param (
      $path = 'G:\BestPractices'  # ENTER A PATH HERE. MAKE SURE THAT IT CONTAINS A MINIMUM OF 1 FILE
    )
    
    New-FileCatalog -Path $path -CatalogFilePath C:\Source.cat -CatalogVersion 2.0
    New-FileCatalog -Path $path -CatalogFilePath C:\Destination.cat -CatalogVersion 2.0
    
    'C:\Source.cat', 'C:\Destination.cat' | Remove-Item
    
    Mode                LastWriteTime         Length Name                          
    ----                -------------         ------ ----                          
    -a----         8/9/2017   3:04 PM           3745 Source.cat                    
    -a----         8/9/2017   3:04 PM           3745 Destination.cat               
    
    
    
    PS> #requires -Version 5.1
    
    # Leave the next line commented out for the first run
    [CmdletBinding()]
    
    param (
      $path = 'G:\BestPractices'  # ENTER A PATH HERE. MAKE SURE THAT IT CONTAINS A MINIMUM OF 1 FILE
    )
    
    New-FileCatalog -Path $path -CatalogFilePath C:\Source.cat -CatalogVersion 2.0
    New-FileCatalog -Path $path -CatalogFilePath C:\Destination.cat -CatalogVersion 2.0
    
    'C:\Source.cat', 'C:\Destination.cat' | Remove-Item
    
    Mode                LastWriteTime         Length Name                          
    ----                -------------         ------ ----                          
    -a----         8/9/2017   3:05 PM           3745 Source.cat                    
    -a----         8/9/2017   3:05 PM           3745 Destination.cat
    Don't see any Verbose output here. I can't even find the files it seems to have created?

    Perhaps the Write-Verbose commands are in the CmdLet? But don't know why I didn't get the messqges then.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Lounger
    Join Date
    Dec 2009
    Location
    Gillingham, Dorset, UK
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 11 Posts
    Thanks RG,

    Did you try it in the PS console?

    The catalog files get deleted in order to clean up. If you want to see the files you will need to comment out or delete the last line:

    'C:\Source.cat', 'C:\Destination.cat' | Remove-Item

    Thanks. I'll try to run the script in the ISE and see if I get the same as you.

    Cliff
    Last edited by Cliff.H; 2017-08-09 at 14:47.

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,081
    Thanks
    429
    Thanked 1,621 Times in 1,462 Posts
    Cliff,

    Here's the output from the Console, not different!

    Code:
    PS> G:\BEKDocs\Scripts\CliffTest.ps1
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----         8/9/2017   4:36 PM           3745 Source.cat
    -a----         8/9/2017   4:36 PM           3745 Destination.cat
    
    
    PS> G:\BEKDocs\Scripts\CliffTest.ps1
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----         8/9/2017   4:36 PM           3745 Source.cat
    -a----         8/9/2017   4:36 PM           3745 Destination.cat
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Lounger
    Join Date
    Dec 2009
    Location
    Gillingham, Dorset, UK
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 11 Posts
    RG,
    The script needs to be run with the -Verbose switch.

    Thanks

    Cliff

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,081
    Thanks
    429
    Thanked 1,621 Times in 1,462 Posts
    Duh!

    UnCommented Cmdlet Binding:
    Code:
    PS> G:\BEKDocs\Scripts\CliffTest.ps1 -verbose
    VERBOSE: Adding file 'G:\BestPractices\Building Reusable Tools.md' to the catalog. Relative path of file in catalog
    is 'Building Reusable Tools.md'.
    VERBOSE: Adding file 'G:\BestPractices\Error Handling.md' to the catalog. Relative path of file in catalog is 'Error
    Handling.md'.
    VERBOSE: Adding file 'G:\BestPractices\Introduction.md' to the catalog. Relative path of file in catalog is
    'Introduction.md'.
    VERBOSE: Adding file 'G:\BestPractices\Language, Interop and .Net.md' to the catalog. Relative path of file in
    catalog is 'Language, Interop and .Net.md'.
    VERBOSE: Adding file 'G:\BestPractices\Metadata, Versioning, and Packaging.md' to the catalog. Relative path of file
    in catalog is 'Metadata, Versioning, and Packaging.md'.
    VERBOSE: Adding file 'G:\BestPractices\Naming Conventions.md' to the catalog. Relative path of file in catalog is
    'Naming Conventions.md'.
    VERBOSE: Adding file 'G:\BestPractices\Output and Formatting.md' to the catalog. Relative path of file in catalog is
    'Output and Formatting.md'.
    VERBOSE: Adding file 'G:\BestPractices\Performance.md' to the catalog. Relative path of file in catalog is
    'Performance.md'.
    VERBOSE: Adding file 'G:\BestPractices\Security.md' to the catalog. Relative path of file in catalog is
    'Security.md'.
    VERBOSE: Adding file 'G:\BestPractices\TODO.md' to the catalog. Relative path of file in catalog is 'TODO.md'.
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----         8/9/2017   5:10 PM           3745 Source.cat
    VERBOSE: Adding file 'G:\BestPractices\Building Reusable Tools.md' to the catalog. Relative path of file in catalog
    is 'Building Reusable Tools.md'.
    VERBOSE: Adding file 'G:\BestPractices\Error Handling.md' to the catalog. Relative path of file in catalog is 'Error
    Handling.md'.
    VERBOSE: Adding file 'G:\BestPractices\Introduction.md' to the catalog. Relative path of file in catalog is
    'Introduction.md'.
    VERBOSE: Adding file 'G:\BestPractices\Language, Interop and .Net.md' to the catalog. Relative path of file in
    catalog is 'Language, Interop and .Net.md'.
    VERBOSE: Adding file 'G:\BestPractices\Metadata, Versioning, and Packaging.md' to the catalog. Relative path of file
    in catalog is 'Metadata, Versioning, and Packaging.md'.
    VERBOSE: Adding file 'G:\BestPractices\Naming Conventions.md' to the catalog. Relative path of file in catalog is
    'Naming Conventions.md'.
    VERBOSE: Adding file 'G:\BestPractices\Output and Formatting.md' to the catalog. Relative path of file in catalog is
    'Output and Formatting.md'.
    VERBOSE: Adding file 'G:\BestPractices\Performance.md' to the catalog. Relative path of file in catalog is
    'Performance.md'.
    VERBOSE: Adding file 'G:\BestPractices\Security.md' to the catalog. Relative path of file in catalog is
    'Security.md'.
    VERBOSE: Adding file 'G:\BestPractices\TODO.md' to the catalog. Relative path of file in catalog is 'TODO.md'.
    -a----         8/9/2017   5:10 PM           3745 Destination.cat
    Commented Out CmdLet Binding:
    Code:
    
    PS> G:\BEKDocs\Scripts\CliffTest.ps1 -verbose
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----         8/9/2017   5:11 PM           3745 Source.cat
    -a----         8/9/2017   5:11 PM           3745 Destination.cat
    Sorry about that...

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    Lounger
    Join Date
    Dec 2009
    Location
    Gillingham, Dorset, UK
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 11 Posts
    No, that's fine. Thanks for testing and confirming that it is not my environment that is causing this anomaly.

    I tried it in the ISE, and I get the same result.

    Thanks again
    Cliff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •