<h2>How to run powershell script in patterns</h2><br/><div style="overflow-x:auto"><article><div ><h3 >Issue </h3><section><p style="padding-left: 40px;">Powershell Script can be run from the patterns as and when required. This will give the flexibility to run the desired scripts on the server, data can be fetched and used in the pattern. This can also be used to populate CMDB with the required information.</p></section></div><div ><h3 >Release</h3><section><p style="padding-left: 40px;">All Versions.</p></section></div><div ><h3 >Resolution</h3><section><ol style="list-style-position: inside;"><li>Code similar to the below one can be used in EVAL to run PowerShell script.</li></ol> <p style="padding-left: 80px;"><span style="font-family: 'courier new', courier;">EVAL(</span><br /><span style="font-family: 'courier new', courier;">def ip = com.snc.sw.context.support.net.IPUtils.getLocalIp();</span><br /><span style="font-family: 'courier new', courier;">def factory = new com.snc.sw.providers.DiscoveryProviderFactory();</span><br /><span style="font-family: 'courier new', courier;">def wmi =factory.create(com.snc.sw.dto.ProviderType.WMI, null);</span><br /><span style="font-family: 'courier new', courier;">wmi.setHost(ip);</span><br /><span style="font-family: 'courier new', courier;">return wmi.executeCommand("powershell.exe \"Get-module -ListAvailable\"");</span><br /><span style="font-family: 'courier new', courier;">)</span></p> <p style="padding-left: 80px;"><span style="font-family: 'courier new', courier;"><img style="border: 1px solid black; align: baseline;" src="sys_attachment.do?sys_id=f5e57c0ddb8478d0fec4fb24399619e8" width="835" height="374" align="baseline" border="1" /></span></p> <p style="padding-left: 40px;">2. Otherway is to select "Command" from operations and directly provide PowerShell commands as below:</p> <p style="padding-left: 80px;">Example 1: <span style="font-family: 'courier new', courier;">Powershell \" get-process | get-member \"</span><br />Example 2: <span style="font-family: 'courier new', courier;">Powershell \" Get-ChildItem Cert:\ -Recurse -Force | Select-Object -Property Thumbprint,FriendlyName \"</span></p></section></div></article></div>