Integrating PowerShell into NeoVisualWin - Forum

Forum Navigation
You need to log in to create posts and topics.

Integrating PowerShell into NeoVisualWin

Hi overthere,

There are a lot of new services based on the PowerShell enviroment.

I recreated a simple sample in order to show how to integrate PowerShell with NBW.

This sample was tested on Win7 and newer

First step: create a .PS1 file.

PS1 is the extension used by PowerShell in order to execute the scripts.

This sample was created based on the Function Library of NVW, to execute a FTP commands.

The NBW  function script is:

FileWrite "[TmpDir]\ftp.ps1" "All" "$source = [#34][FileName][#34]"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$target = [#34]ftp://yourFTPserver.com/yourFolder/File_[date24]_[time].jpg[#34]"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$client = New-Object System.Net.WebClient"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$client.Credentials = New-Object System.Net.NetworkCredential([#34]YourFTPAccount[#34], [#34]yourFTPPass[#34])"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$client.UploadFile($target, $source)"

Obviously, you must change or define the Source, Target, Server, User and Pass variables.

 

Second Step: Create a  .BAT file

In order to send the correct syntax to PowerShell

The sample is:

FileWrite "!c:\MyFolder\send.bat" "All" "powershell -ExecutionPolicy Unrestricted -File c:\MyFolder\ftp.ps1"

 

Third step: run the .BAT program

Run "!c:\MyFolder\send.bat" "" "Hidden" "" ""

This scripts do the job.

In the practice, copy all actions into a new function library with this lines:

FileWrite "[TmpDir]\ftp.ps1" "All" "$source = [#34][FileName][#34]"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$target = [#34]ftp://yourFTPserver.com/yourFolder/File_[date24]_[time].jpg[#34]"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$client = New-Object System.Net.WebClient"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$client.Credentials = New-Object System.Net.NetworkCredential([#34]YourFTPAccount[#34], [#34]yourFTPPass[#34])"
FileWrite "[TmpDir]\ftp.ps1" "Append" "$client.UploadFile($target, $source)"

FileWrite "!c:\MyFolder\send.bat" "All" "powershell -ExecutionPolicy Unrestricted -File c:\MyFolder\ftp.ps1"

Run "!c:\misfotos\send.bat" "" "Hidden" "" ""

Then, recreate the variables you use with your own idea, and addapt this sample for your use.

 

Greetings from Buenos Aires,

David de Argentina

 

 

 

 

luishp, HPW and Darbdenral have reacted to this post.
luishpHPWDarbdenral

Upssss...

change this line:

FileWrite "!c:\MyFolder\send.bat" "All" "powershell -ExecutionPolicy Unrestricted -File c:\MyFolder\ftp.ps1"
to this one:
FileWrite "!c:\MyFolder\send.bat" "All" "powershell -ExecutionPolicy Unrestricted -File [TmpDir]\ftp.ps1"
:-)
luishp, Vadim and 3 other users have reacted to this post.
luishpVadimHPWCN_Icemanemo

Hello @daviddeargentina , very interesting your contribution. I leave you a repository of scripts in Powershell that you can surely take advantage of ;-)

https://github.com/fleschutz/PowerShell

Greetings

luishp, Vadim and 3 other users have reacted to this post.
luishpVadimCN_IcemanagilosDarbdenral

@emmanuel-fernandez

WOW !!!

Thanks a  bunch !