Running Powershell Scripts from ccmcache folder

Timtohy Ferrara 21 Reputation points
2021-10-22T21:15:31.763+00:00

I'm trying to run a script as part of my sccm deployment that imports files from the cache folder. When the script runs it says the system cannot find the file specified.

$toolTest = (Test-Path "C:\Program Files\RedHat\java-11-openjdk-jre-11.0.12-1\bin\keytool.exe")
$tool = 'C:\Program Files\RedHat\java-11-openjdk-jre-11.0.12-1\bin\keytool.exe'
$ToolTest2 = (Test-Path "F:\Program Files\RedHat\bin\keytool.exe")
$tool2 = 'F:\Program Files\RedHat\bin\keytool.exe'

IF ($tooltest -eq $True)
{
$PSScriptRoot
& $tool -importcert -alias "EWSINT1" -file "$PSScriptRoot\root.cer" -keystore "C:\Program Files\RedHat\java-11-openjdk-jre-11.0.12-1\lib\security\cacerts" -storepass "changeit" -noprompt -trustcacerts
& $tool -importcert -alias "EWSINT2" -file "$PSScriptRoot\issuing.cer" -keystore "C:\Program Files\RedHat\java-11-openjdk-jre-11.0.12-1\lib\security\cacerts" -storepass "changeit" -noprompt -trustcacerts
& $tool -importcert -alias "EWSINT3" -file "$PSScriptRoot\intermediate.cer" -keystore "C:\Program Files\RedHat\java-11-openjdk-jre-11.0.12-1\lib\security\cacerts" -storepass "changeit" -noprompt -trustcacerts
}

IF ($tooltest2-eq $True)
{
$PSScriptRoot
& $tool2 -importcert -file "$PSScriptRoot\root.cer" -keystore "F:\Program Files\RedHat\lib\security\cacerts\lib\security\cacerts" -storepass "changeit" -noprompt -trustcacerts
& $tool2 -importcert -file "$PSScriptRoot\issuing.cer" -keystore "F:\Program Files\RedHat\lib\security\cacerts\lib\security\cacerts" -storepass "changeit" -noprompt -trustcacerts
& $tool2 -importcert -file "$PSScriptRoot\intermediate.cer" -keystore "F:\Program Files\RedHat\lib\security\cacerts\lib\security\cacerts" -storepass "changeit" -noprompt -trustcacerts
}

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,551 questions
Microsoft Configuration Manager Application
Microsoft Configuration Manager Application
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Application: A computer program designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end users.
493 questions
Microsoft Configuration Manager
{count} votes

Accepted answer
  1. MotoX80 34,426 Reputation points
    2021-10-26T17:55:59.61+00:00

    but the script isn't running from the ccmcache folder.

    What specifically "isn't running"? Do you get an error?

    As Garth answered, you need to add logging and troubleshooting code to the script to determine what it's doing.

    Start by adding a transcript.

    Start-Transcript -path C:\Windows\Temp\MyScript.log
    ...... the rest of your script....
    Stop-Transcript
    

    Add in directory listings to see what files are there.

    "Directory list of current directory"
    get-childitem  
    "Directory list of script root"
    get-childitem -Path $PSScriptRoot 
    

    Add in more Test-Path commands to verify that the files you expect to find are actually there.


2 additional answers

Sort by: Most helpful
  1. Garth 5,801 Reputation points
    2021-10-23T00:58:36.68+00:00

    How exactly are you running this? Why not add logging to the script to see what is happening.

    1 person found this answer helpful.

  2. Limitless Technology 39,676 Reputation points
    2021-10-26T20:02:32.333+00:00

    Hello @Timtohy Ferrara

    Could you try to enable Verbose in your script, a detailed output would definitely help the community to understand what is failing, you can achieve it by running the next at the top:

    $VerbosePreference="Continue"  
    

    Hope this helps with your query,

    ----------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.