Normal Topic PowerShell (Read 11702 times)
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
PowerShell
Oct 28th, 2019 at 5:06am
Print Post Print Post  
Has anyone successfully run a PowerShell script file from within Sesame?

For example, something similar to one of the following:
Code
Select All
CreateAProcess("powershell -File .\test.ps1")
     -or-
@RedirectProcess("powershell -File .\test.ps1", "") 



I can't seem to get it to work.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: PowerShell
Reply #1 - Oct 28th, 2019 at 3:46pm
Print Post Print Post  
Hi Carl,

You may need to edit paths to work on your system but...

Code
Select All
CreateaProcess("c:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -File C:\Sesame2\Test.ps1") 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
actiontech
Full Member
***
Offline



Posts: 173
Joined: Apr 10th, 2016
Re: PowerShell
Reply #2 - Oct 30th, 2019 at 1:38pm
Print Post Print Post  
I don't remember if I ever got it to work correctly or if it was "within" Sesame, but I created a .txt file that I edited from the Sesame programming then inserted that .txt file into a powershell prompt.

This was part of a For-Next loop:
Code
Select All
If @XResultSetValue(vRS, "H_No") > " " And @XResultSetValue(vRS, "Address") > " " And @XResultSetValue(vRS, "Zip") > " " Then
			{
				vAdd = @REPLACE(@XResultSetValue(vRS, "H_No") + "+" + @XResultSetValue(vRS, "Address") + "%2C+" + @XResultSetValue(vRS, "City") + "%2C+FL+" + @XResultSetValue(vRS, "Zip"), " ", "+")
				vFile = "C:\Sesame2\GeoCode.ps1"
				vData = "$doc = New-Object System.Xml.XmlDocument; $doc.Load(" + @Chr(34) + "https://maps.googleapis.com/maps/api/geocode/xml?address=" + vAdd +
				"&key=AIzaSyAdzPdX6kBkjY_5H0H_0IF1Ytb3Z6TQ5pY" + @Chr(34) + "); $latlng = $doc.GeocodeResponse.result.geometry.location.lat + ',' +
				$doc.GeocodeResponse.result.geometry.location.lng; Out-File -filepath C:\Sesame2\GeoCode.txt -inputObject $latlng -encoding " + @Chr(34) + "ASCII"
				+ @Chr(34)
				FileOverWrite(vFile, vData)
				vLatLng = @Shell("powershell " + @Chr(34) + vFile + @Chr(34))
				vDoc = @Insert("C:\Sesame2\GeoCode.txt")
				WriteLn(vDoc)
				//WriteLn("http://maps.googleapis.com/maps/api/staticmap?size=640x640&markers=color:red" + + "&key=AIzaSyAdzPdX6kBkjY_5H0H_0IF1Ytb3Z6TQ5pY"

				vAdds = @AppendStringArray(vAdds, @XResultSetValue(vRS, "H_No") + "+" + @XResultSetValue(vRS, "Address") + "%2C+" +
				@XResultSetValue(vRS, "City") + "%2C+FL+" + @XResultSetValue(vRS, "Zip"))
			}
 



Once again though, not sure if it worked, and it's been a long time since I worked with it. I think it was still a work in progress.
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: PowerShell
Reply #3 - Dec 24th, 2019 at 11:53pm
Print Post Print Post  
Thanks guys. I've been so busy. I just now got back to check the forum. I'd forgotten about this.

Ray, I tried your suggestion, but still no results. The same command that works from the command line, does not work from within Sesame.

I've tried:
Code
Select All
@RedirectProcess("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File S:\Sesame2\Test.ps1", "")

@Shell("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File S:\Sesame2\Test.ps1")

CreateAProcess("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File S:\Sesame2\Test.ps1") 


I've even tried adding "cmd /c" in front of each of those, but no luck.



Aha! Got it working.

Ray, your post helped me rethink what was going on with the PowerShell command. To run a PowerShell file, you need to set the ExecutionPolicy within PowerShell to allow it. I had done that for "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", but apparently even though I specified that path, when Sesame calls it, the OS delivers up the one in SysWOW64, instead. Once I set the ExecutionPolicy in the SysWOW64 version, I was able to run it with either of the following commands:
Code
Select All
// Works. Sesame waits until the black DOS window is finished displaying.
@Shell("powershell -File .\test.ps1")

// Works. Sesame does NOT wait until the blue PW window is finished displaying.
CreateAProcess("powershell -File .\test.ps1") 



Thank you!  Smiley
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: PowerShell
Reply #4 - Jan 8th, 2020 at 2:30pm
Print Post Print Post  
Wow, that ... that's very clever!
  
Back to top
IP Logged