Foreach Loop question RRS feed

  • Question

  • I am trying to do a  loop on all the files listed in this directory C:\OpenSSL-Win64\bin\pemfolder. Namely, I want to go through each file and run it through the certutile.exe -encode to convert it from a .cer to a .pem.  I am thinking about doing it this way. However, I am not sure how to get the output file named something similar to the input file that I am giving it any ideas?

    Get-ChildItem C:\OpenSSL-Win64\bin\pemfolder -OutVariable pemfile

    foreach ($pem in $pemfile)
           certutil.exe -encode  $pemfile <output file>

    Tuesday, March 20, 2018 6:13 PM


  • Something such as:

    Get-ChildItem "C:\OpenSSL-Win64\bin\pemfolder\*.cer" | ForEach-Object {
      certutil -encode $_.FullName ("{0}\{1}.pem" -f $_.DirectoryName,$_.BaseName)

    -- Bill Stewart [Bill_Stewart]

    Tuesday, March 20, 2018 6:20 PM

All replies