F
F
Fenderas2014-12-25 18:03:24
PowerShell
Fenderas, 2014-12-25 18:03:24

How to pass execution results/variables between two different scripts?

Good day everyone. All functionality is implemented on the Windows Server 2008 r2 platform with Powershell version 4.
There is a Wishlist - to execute the code by the remote machine.
Everything works fine via:

Invoke-Сommand -Session $session -FilePath "ПутьКСкрипту"

Wishlist began to grow and now I need to implement the following logic:
1. The first script performs certain operations in AD, generates parameters for executing code on a remote machine, calls the second script with these parameters.
2. The second script performs a number of specific actions with hard disks - it makes partitioning. The new drive letter is generated on this remote machine and must be passed back to the calling script.
3. The first script receives this data and finishes working with the GPO, which just requires the received drive letter from the remote machine.
All my trouble is that I do not understand how to return the received letter from the remote machine.
I don't want to mute all the output of the second script and do return БУКВА, because I need to read what's going on there.
Two options come to mind:
1. Exchange between them (scripts) through files, but this is somehow crooked.)
2. You can also get a list of available letters from a remote machine and make a choice on the side of the first script, then the output of the letter and you don’t have to catch it at all, I’ll get by. :)
Maybe someone will tell you another, 3rd way? )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2014-12-26
@rbobot

First option. Create a custom object with fields to be returned, like so:
[pscustomobject]@{
SeverName = $Name;
DiskLetter = $DiskLetter;
}
Then serialize it into xml via Export-Clixml $report
Upload it to the ball where the first script will look for it.
Second option. Use TCP client/server communication.
For example, poshcode.org/4601 has more options online.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question