Pass Variable Informatuon from one Pssession to another.

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Daniel Daniel 3 months ago.

  • Author
    Posts
  • #65157
    Profile photo of Daniel
    Daniel
    Participant

    Hello everone

    I write a twit: https://twitter.com/Lindegaard13/status/834786426441052161
    How can I pass Variable $a from session A1(local) to session B1 and then access the Variable $a from within session B1 with #powershell ?

    A little more information for this quistion:

    My challenge is the following. I have several File server where we have some File screening running. every-time file X hits(Created) I would like to scoop that file name (Fullname) and it'w owner up and pass that information to one central location.
    That central location will then process the data, and save to a database.

    The database part and so on it good, but I can't figure out how to pass the information from my session to a remove session, that then can process the data.

  • #65160
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You have to do this when you open the session, via Invoke-Command's -Argument parameter.

    Invoke-Command -ScriptBlock {
    Param($x,$y)
    # your script uses $x and $y
    } -Argument $a,$b

    $a and $b are local variables, and will be mapped to $x and $y in the remote script block.

  • #65176
    Profile photo of Daniel
    Daniel
    Participant

    That I understand if I like to run something on a remote server.

    I like to:

    Server 1:(Fileserver)
    Runs in to a file x, execute File screening, take that data and send it to server 2. Using PSsession, namespace or something. Not store it to a file that server 2 can access.

    Server 2, PS session name (what ever): Have a look for data in "bucket", if there is data, take the data (File Object), and store it in a array, variable (Bucket), for further use of some sort. I like to have a service or a Job (something) that operate in a space, that multibol servers can access and store data to, where is some, so this service can process it as it comes.

    I have played around with New-Pssession and store that in a variable, and use it in invoke-command -session $session variable.
    But When I like to access this session it's disconnected or there is no data in session.

    I hope I explain my self okey? Or is this

  • #65178
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Sessions will persist their data while they're alive, but there is a time-out. A session that has sat idle for too long will disconnect and cease to exist – which means you lose the data.

    Additionally, there is not a good or easy way to have multiple servers accessing a given session. Sessions are tied to a user account.

    I think you actually -do- want a service – like, an actual Windows background service – to do this. Sessions were not meant for this kind of use. You could also consider using a SQL Server or other database to store your data.

  • #65181
    Profile photo of Daniel
    Daniel
    Participant

    So in the Powershell world, is there a way, "Software Client A", can talk to "Software Service B"? As Sessions is out of the picture?
    I have created something that write the data to a CSV file and a SQL database, but like to have it passed the data direct to a services, running in another Session/namespace/ something...

    I have looket at C# Namespaces, as I understand it, it can us created and used with Powershell, but haven't found much about it, and the use I'm looking for.

You must be logged in to reply to this topic.