-
1. Re: Using .CSV files for PowerShell Scripts in vRO
eoinbyrne Sep 16, 2019 12:36 AM (in response to Vitality1)The MimeAttachment is a JSObject which wraps the CSV file content along with MimeType information about what the content and the entire object is *really* a Java object underneath anyway. When you pass it to the PowerShell invocation like that the vRO system will end up just sending the Java Object type and reference as you've seen.
The important thing to remember here is that the PowerShellHost is an external system to vRO and is accessed remotely so any call to PowerShell which refers to a file will require the file to exist on the filesystem which is local to where it is running. As you've said yourself, this will be a bit more scripting to make the local file.
How big is the CSV file? If it's not too large (< 0.5MB) then you can probably just pass the content as as string to PowerShell? e.g.,
".\Script.ps1 -CSVFileCotnent <CSVFIle content as one long string>"
I've done this before for relatively small amounts of data but did find that PowerShell can be picky about escapes so I just base64 encoded the content and then had my script decode it before use like this - [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String("$b64EncodedData"));
There is also the GuestScriptManager package which provides support for
- Creating files in the Guest
- Executing a process in the Guest
It depends on the VMware tools APIs but tools will probably be present in the VM anyway
-
2. Re: Using .CSV files for PowerShell Scripts in vRO
Vitality1 Sep 16, 2019 2:58 PM (in response to eoinbyrne)Thanks for the explanation. The file is max under 5 KB, usually just 1-2 KB.
Passing the content as a string could work I think, would have to rewrite my script a little bit as it's looking for .CSV
The GuestScriptManager package, is there an example out there I can see of using this to put a file on a PSHost?
-
3. Re: Using .CSV files for PowerShell Scripts in vRO
eoinbyrne Sep 17, 2019 1:26 AM (in response to Vitality1) -
4. Re: Using .CSV files for PowerShell Scripts in vRO
Vitality1 Sep 17, 2019 2:44 PM (in response to eoinbyrne)Ok I see the package. I made a duplicate of the workflow, and I'm trying to understand this. So I would do something like this for the inputs?
vmUsername: DOMAIN\Username
vmPassword: Password
vm: PowerShell Host
dirPath: C:\
prefix: file
suffix: .csv
Something like this? If so, the part I'm not following is how do I actually get data into C:\file.csv after it's created? Kick off PowerShell script workflow to feed the data back in?
-
5. Re: Using .CSV files for PowerShell Scripts in vRO
eoinbyrne Sep 18, 2019 1:26 AM (in response to Vitality1)Yep, your inputs look fine there.
Actually, I pointed you at a helpful workflow but not the most useful one for what you want. The GSM package achieves a lot of what it does by doing the things like the following
- Permits you to store a script file (or any any file) as a vRO ResourceElement
- Will write that file out to the guest by doing
- Create a temporary file on the vRO server using System.createTempFile(<suffix>);
- Writes the content of the ResourceElement to that temp file
- Copies the temporary file from vRO to the Guest with a defined name and path in the guest FS
- Deletes the temporary file from the vRO server
The screengrab below shows where to find this
You will need to unpick the code you want but it's mostly there in that section.
Incidentally, I forgot to ask where the CSV content is coming from - is it static or generated somewhere outside vRO and the Guest in question? I ask I forgot to suggest getting something else to write the file onto the PowerShellHost - perhaps via UNC file copy?
-
6. Re: Using .CSV files for PowerShell Scripts in vRO
Vitality1 Oct 21, 2019 7:11 PM (in response to eoinbyrne)Thanks for all your help with this eoinbyrne. I was able to get a working version of this with your help and some other co-workers. Will update post and mark answer soon.