{"id":2046,"date":"2016-08-04T00:22:23","date_gmt":"2016-08-04T00:22:23","guid":{"rendered":"http:\/\/leinss.com\/blog\/?p=2046"},"modified":"2016-08-04T00:22:23","modified_gmt":"2016-08-04T00:22:23","slug":"deploy-infor-xa-client-with-powershell","status":"publish","type":"post","link":"https:\/\/leinss.com\/blog\/?p=2046","title":{"rendered":"Deploy Infor XA Client with PowerShell"},"content":{"rendered":"<p>Here was a fun installer to get working silently. \u00a0This one uses something called InstallAnywhere. \u00a0It is a java based installer and if you Google <em>InstallAnywhere silent<\/em>, you will happen upon several command line options. \u00a0The correct set for this version of the installer (<em>2009 version<\/em>)\u00a0can be found <a href=\"http:\/\/helpnet.flexerasoftware.com\/installanywhere2012\/roottopic.htm#CSHID=helplibrary%2Fia_ref_command_line_install_uninstall.htm|StartTopic=Content%2Fhelplibrary%2Fia_ref_command_line_install_uninstall.htm\">here<\/a>.<\/p>\n<p>Here&#8217;s the command to install it silently:<\/p>\n<p><code>xaclient_Hgenas400_P36001.exe -i silent<\/code><\/p>\n<p>We can also record settings into a file and play those back. \u00a0To record:<\/p>\n<p><code>xaclient_Hgenas400_P36001.exe -r C:\\temp\\powerlink.properties<\/code><\/p>\n<p>Finally, we end up with this to install silently:<\/p>\n<p><code>xaclient_Hgenas400_P36001.exe -i silent -f powerlink.properties<\/code><\/p>\n<p>The installer launches the program at the end: I didn&#8217;t see any settings to turn that off.<\/p>\n<p>The PowerShell code starts off pretty boring:<\/p>\n<p><code>$p = start-process .\\xaclient_Hgenas400_P36001.exe -ArgumentList '-i silent -f powerlink.properties' -Wait -Passthru<br \/>\nicacls *.lnk \/grant:r everyone:RX<br \/>\ncopy-item *.lnk -Destination C:\\users\\public\\desktop<\/code><\/p>\n<p>We kick off the installer, tell PowerShell to wait for the process to end and return an object (-Passthru), grant Everyone read and execute rights to the icon and then copy that icon to the the system shared desktop.<\/p>\n<p>If you execute this code, however, the PowerShell script never progresses. This is because the installer runs the full program as a child process from the installer\u00a0and until the\u00a0program is closed, it waits for the installer&#8217;s termination forever.<\/p>\n<p>The program is Java based and executes two processes:\u00a0Infor XA Power-Link and javaw. \u00a0We can create a loop waiting for these two processes, then kill them:<\/p>\n<p><code>Do {<\/code><\/p>\n<p><code>$status = Get-Process -Name \"Infor XA Power-link\" -ErrorAction SilentlyContinue<br \/>\n<\/code><br \/>\n<code>If (!($status)) {<br \/>\nWrite-Host 'Waiting for process to start' ;<br \/>\nStart-Sleep -Seconds 2<br \/>\n}<\/code><\/p>\n<p><code>Else { Write-Host 'Process has started' ;<br \/>\n$started = $true<br \/>\nStop-Process -name \"Infor XA Power-Link\"<br \/>\nStop-Process -name javaw<br \/>\n}<\/code><\/p>\n<p><code>}<br \/>\nUntil ( $started )<\/code><\/p>\n<p>I picked 2 seconds\u00a0to keep checking the process list and not hammer the CPU. \u00a0So obviously for this to work, we need to remove the -Wait and -Passthru options from Start-Process, but then how do we check if the program installed OK? \u00a0We can check if the program executable exists and then return the proper exit code:<\/p>\n<p><code>if (Test-Path('C:\\infor\\ERP XA Client\\Infor XA Power-Link.exe')) {<br \/>\n$LASTEXITCODE = 0<br \/>\nexit 0<br \/>\n} #end if<\/code><\/p>\n<p><code>else {<br \/>\n$LASTEXITCODE = 1<br \/>\nexit 1<br \/>\n} #end else<\/code><\/p>\n<p>Anything other than exit code 0 is usually a failure (<em>MSIs usually return\u00a0exit code\u00a03010 to indicate a reboot<\/em>).<\/p>\n<p>Using the exit command with a specific number seems to pass the exit code properly back to SCCM. \u00a0Based on my Google-fu: it&#8217;s then best to wrap your PowerShell script in a batch file and then fire that from SCCM to get the exit code of any non-native command ran from within a PowerShell script:<\/p>\n<p><code>powershell -executionpolicy bypass -file .\\install_powerlink.ps1<br \/>\necho %errorlevel%<br \/>\nexit \/b %errorlevel%<\/code><\/p>\n<ul>\n<li>Soli Deo Gloria<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Here was a fun installer to get working silently. \u00a0This one uses something called InstallAnywhere. \u00a0It is a java based installer and if you Google InstallAnywhere silent, you will happen upon several command line options. \u00a0The correct set for this version of the installer (2009 version)\u00a0can be found here. Here&#8217;s the command to install it &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/leinss.com\/blog\/?p=2046\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Deploy Infor XA Client with PowerShell&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[11],"tags":[],"class_list":["post-2046","post","type-post","status-publish","format-standard","hentry","category-powershell"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7wiG8-x0","jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2046"}],"version-history":[{"count":11,"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2046\/revisions"}],"predecessor-version":[{"id":2057,"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2046\/revisions\/2057"}],"wp:attachment":[{"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leinss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}