VMware Cloud Community

Tip: Temporary Data Storage in a PowerShell Container at Runtime

Based on the discussion about Access vRO Filesystem using Polyglot from @imtrinity94 here an approach how to store data in a PowerShell container at the runtime.

The interesting thing about this approach is that the PowerShell CmdLets do not work, but calling the dotNET methods works fine. It's not clear to me if it is a bug or a feature.

Another interesting thing is that it seems to be necessary to create a directory, in this example temp. Writing directly to /run/vco-polyglot/function did not succeed in my case. 

Here the commented code:


# Begin-----------------------------------------------------------------

function Handler($context, $inputs) {
  $inputsString = $inputs | ConvertTo-Json -Compress;
  # Write-Host "Inputs were $($inputsString)";

  # Create temp directory in /run/vco-polyglot--------------------------
  [System.String]$directory = "temp";
  # New-Item -ItemType "directory" -Force -Path "$($directory)";
  if ([System.IO.Directory]::Exists($directory) -eq $false) {
    Write-Host "Create directory $($directory)";

  # Create file Test.txt in temp directory with text--------------------
  [System.String]$writeText = "This is a test";
  [System.String]$path = "$($directory)/Test.txt";
  [System.IO.File]::WriteAllText($path, $writeText);

  # List all files in temp directory------------------------------------
  [System.String[]]$files = [System.IO.Directory]::GetFiles($directory);
  forEach ($file in $files) {
    Write-Host $file;

  # Read the content from the Text.txt file in temp directory-----------
  [System.String]$readText = [System.IO.File]::ReadAllText($path);
  Write-Host $readText;

  # Delete directory temp-----------------------------------------------
  if ([System.IO.Directory]::Exists($directory)) {
    Write-Host "Delete directory $($directory)";
    [System.IO.Directory]::Delete($directory, $true);

  $output = @{status = "done"}
  return $output;

# End-------------------------------------------------------------------


Here my test result with the vRealize Automation



In a PowerShell container we have the possibility, by using dotNET methods, to access the file system in the path /run/vco-polyglot/function. This can be very helpful for certain requirements. However, we must not forget that the container with its content is also deleted at the end of the automation process. That is why this approach can only be used for temporary storage.

More interesting information at blog.stschnell.de

2 Replies

The root filesystem of the container is writeable:

function Handler($context, $inputs) {

    $dir = New-Item -ItemType "directory" -Force -Path "/mydata"
    Get-Date | Out-File -FilePath "/mydata/date.txt"
    Get-Content -Path "/mydata/date.txt" | Write-Host

    return @{}


You can use it in Python as well, if needed.


Hello @xian_,

thank you very much for your reply and experience sharing.

Interesting that it works now. I tried it at HOL with release 8.5.1 a longer time ago and I tried it now with release 8.13.1. It didn't work then, but now it works, good to know.

Best regards

More interesting information at blog.stschnell.de

0 Kudos