cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Anyone Managing their Windchill Installation with Powershell?

bcedar
14-Alexandrite

Anyone Managing their Windchill Installation with Powershell?

We have our Windchill servers deployed in Windows environments and have been stuck using command prompt and batch files to manage our servers...  Not too long ago, we started on a journey of pipeline based configuration using Azure Devops.

 

Officially PTC says they don't support Powershell.
https://www.ptc.com/en/support/article/CS323668?&language=en&posno=3&q=powershell&source=search

But I think I figured out how to at least get the environment variables from that handy windchill2.bat script.

 

foreach ($line in $(cmd.exe /c "E:\ptc\Windchill\bin\windchill2.bat setenv && set")) {
    [System.Environment]::SetEnvironmentVariable($line.split("=")[0], $line.split("=")[1], [System.EnvironmentVariableTarget]::Process)
}

 

Comment below on how you're managing your deployments?  What language(s) are you using?

3 REPLIES 3
bcedar
14-Alexandrite
(To:bcedar)

I have expanded this powershell script to be wrapped into an if statement incase it gets called over and over.  You don't want to just keep expanding on your path.

This is a snippet from my Enter-WindchillShell.ps1 script.

if (
    -not (
        (Get-Command 'ant' -ErrorAction SilentlyContinue) -and 
        (Get-Command 'windchill' -ErrorAction SilentlyContinue) -and 
        (Get-Command 'xconfmanager' -ErrorAction SilentlyContinue) -and 
        (Get-Command 'windchill2.bat' -ErrorAction SilentlyContinue) -and 
        $ENV:WT_HOME
    )
) {
    $WT_HOME = Get-Item -Path E:\ptc\Windchill
    foreach ($line in $(cmd.exe /c "$WT_HOME\bin\windchill2.bat setenv && set")) {
        [System.Environment]::SetEnvironmentVariable($line.split("=")[0], $line.split("=")[1], [System.EnvironmentVariableTarget]::Process)
    }
}

 

DaveBfoot
5-Regular Member
(To:bcedar)

I realise this thread is a bit old but I've not really found any other talk about doing this. 

I've started looking a creating some build scripts for post install configuration using Powershell & I've found I'm able to set the environment variables the same as what a Windchill shell does. They only persist per powershell session which is suitable.

I declare them at the start of the script like this:

$Env:ANT_ARGS = "-noclasspath -logger com.ptc.tools.build.PTCLogger -lib E:\ptc\Windchill_11.1\Windchill\srclib\tool\PtcBuildSupport-ant.jar"
$Env:ANT_HOME = "E:\ptc\Windchill_11.1\Windchill\ant"
$Env:ANT_OPTS = "-Xmx1024m"
$Env:CLASSPATH = "E:\ptc\Windchill_11.1\Windchill\codebase;E:\ptc\Windchill_11.1\Windchill\codebase\WEB-INF\lib\*;E:\ptc\Windchill_11.1\Windchill\lib\*;E:\ptc\Windchill_11.1\Java\lib\tools.jar;E:\ptc\Windchill_11.1\Windchill\tomcat\bin\bootstrap.jar;E:\ptc\Windchill_11.1\Windchill\tomcat\bin\tomcat-juli.jar"
$Env:JAVA_HOME = "E:\ptc\Windchill_11.1\Java"
$Env:Path += ';E:\ptc\Windchill_11.1\Windchill\bin;E:\ptc\Windchill_11.1\Windchill\ant\bin;E:\ptc\Windchill_11.1\Java\jre\bin;E:\ptc\Windchill_11.1\Java\bin'
$Env:PWD = "E:/ptc/Windchill_11.1/Windchill/bin"
$Env:SQLPATH = "E:\ptc\Windchill_11.1\Windchill\db\sql"
$Env:WT_HOME = "E:\ptc\Windchill_11.1\Windchill"

 

Then coming across the mention of windchill2.bat in your post I started looking into what that was & found more info here: https://www.ptc.com/en/support/article/CS49725

That enabled me to be able to add properties via Powershell using the following syntax:

windchill2 -w "E:\PTC\Windchill_12.0\Windchill" --java="E:\Amazon_Corretto_JDK\jdk11.0.11_9\bin\java.exe" xconf -s <property_name>=<property_value> -t codebase/wt.properties -p

 

With the environemnt variables set you can do other things like run ant commands as you would normally from a Windchill shell:

$methodserversvcname = 'PTC_Windchill_MethodServer'
ant -buildfile E:\PTC\Windchill_12.0\Windchill\opt\ntservice\WindchillService.xml install "-DserviceName=$methoderversvcname"

 

Anything requiring cmd or existing bat files you can easily run from Powershell using 'cmd /c' ...

 

So far I've scripted the follwing configs using Powershell:

- Start/stop WDS & import base ldif node for a standalone install 

- Enable WDS as a service, customise process & service name

- Add xconf properties

- Set permanant system environement variables

- Create Apache/Solr/Method Server services & set custom process names

- Modify the user & credentials of the account the service runs as

- Set the mail server & jmx-administrators email list for alerts

 

Next I'm working on scripting some of the HTTPS config & Creo worker/publisher customisation we have.

DaveBfoot
5-Regular Member
(To:DaveBfoot)

Just an update to this:

If you want to use a comma seperated list as a value of an ant command in Powershell (e.g. setting JMX-Administrators email list), you need to add a space & escape character before the comma:

$EmailList = "email1@test.com `,email2@test.com `,email3@test.com"
ant -f $Env:WT_HOME\codebase\modifyMBeanConfig.xml setEmailList -DemailAddresses="$EmailList"

 

And if you want to use openssl.exe, call it with Start-Process:

Start-Process $HttpServerPath\bin\openssl.exe -Argumentlist "req -config $CsrCnf -new -newkey rsa:2048 -nodes -keyout $HttpsKey -out $HttpsCsr" -wait

 

Top Tags