<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help to Convert VBS Script to Powershell for SAS EG Project file with Specific Container in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953253#M45609</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Desktop was upgraded to Windows 11 without the VB Script feature. I need to figure out how to convert the vb script that SAS EG generates to powershell or javascript.&lt;/P&gt;&lt;P&gt;Below is .vbs script that I want to convert to powershell or javascript.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="shell"&gt;Option Explicit
Dim app         ' As SASEGuide.Application

Call dowork

'shut down the app
If not (app Is Nothing) Then
    app.Quit
    Set app = Nothing
End If


Sub dowork()
    On Error Resume Next
    '----
    ' Start up Enterprise Guide using the project name
    '----
    Dim prjName     ' As String
    Dim prjObject   ' As SASEGuide.Project
    Dim containerName     ' As String
    Dim containerObject   ' As SASEGuide.Container
    Dim containerColl     ' As SASEGuide.ContainerCollection

    prjName = "&amp;amp;Networkpath\data_extract_server.egp" ' Project Name
    containerName = "prod_server" ' Container Name
      
    Set app = CreateObject("SASEGObjectModel.Application.8.1")
    If Checkerror("CreateObject") = True Then
        Exit Sub
    End If
    
    Set prjObject = app.Open(prjName,"")
    If Checkerror("App.Open") = True Then
        Exit Sub
    End If
    
        
    '-----
    'Get The Container Collection and Object
    '-----    
    Set containerColl = prjObject.ContainerCollection
    If Checkerror("Project.ContainerCollection") = True Then
        Exit Sub
    End If
    
    Dim i       ' As Long
    Dim count   ' As Long
    count = containerColl.count
    For i = 0 To count - 1
        Set containerObject = containerColl.Item(i)
        If Checkerror("ContainerCollection.Item") = True Then
            Exit Sub
        End If
        
        If (containerObject.Name = containerName) Then
            Exit For
        Else
            Set containerObject = Nothing
        End If
    Next 
    
    If not (containerObject Is Nothing) Then
        '----
        ' Run the Container
        '----
        containerObject.Run
        If Checkerror("Container.Run") = True Then
            Exit Sub
        End If               
    End If
                
    '-----
    ' Save the new project
    '-----
    prjObject.Save
    If Checkerror("Project.Save") = True Then
        Exit Sub
    End If
    
    '-----
    ' Close the project
    '-----
    prjObject.Close
    If Checkerror("Project.Close") = True Then
        Exit Sub
    End If
       
End Sub

Function Checkerror(fnName)
    Checkerror = False
    
    Dim strmsg      ' As String
    Dim errNum      ' As Long
    
    If Err.Number &amp;lt;&amp;gt; 0 Then
        strmsg = "Error #" &amp;amp; Hex(Err.Number) &amp;amp; vbCrLf &amp;amp; "In Function " &amp;amp; fnName &amp;amp; vbCrLf &amp;amp; Err.Description
        'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.
        Checkerror = True
    End If
         
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I looked around but having trouble doing it myself.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2024 16:28:54 GMT</pubDate>
    <dc:creator>sbkp</dc:creator>
    <dc:date>2024-12-11T16:28:54Z</dc:date>
    <item>
      <title>Help to Convert VBS Script to Powershell for SAS EG Project file with Specific Container</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953253#M45609</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Desktop was upgraded to Windows 11 without the VB Script feature. I need to figure out how to convert the vb script that SAS EG generates to powershell or javascript.&lt;/P&gt;&lt;P&gt;Below is .vbs script that I want to convert to powershell or javascript.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="shell"&gt;Option Explicit
Dim app         ' As SASEGuide.Application

Call dowork

'shut down the app
If not (app Is Nothing) Then
    app.Quit
    Set app = Nothing
End If


Sub dowork()
    On Error Resume Next
    '----
    ' Start up Enterprise Guide using the project name
    '----
    Dim prjName     ' As String
    Dim prjObject   ' As SASEGuide.Project
    Dim containerName     ' As String
    Dim containerObject   ' As SASEGuide.Container
    Dim containerColl     ' As SASEGuide.ContainerCollection

    prjName = "&amp;amp;Networkpath\data_extract_server.egp" ' Project Name
    containerName = "prod_server" ' Container Name
      
    Set app = CreateObject("SASEGObjectModel.Application.8.1")
    If Checkerror("CreateObject") = True Then
        Exit Sub
    End If
    
    Set prjObject = app.Open(prjName,"")
    If Checkerror("App.Open") = True Then
        Exit Sub
    End If
    
        
    '-----
    'Get The Container Collection and Object
    '-----    
    Set containerColl = prjObject.ContainerCollection
    If Checkerror("Project.ContainerCollection") = True Then
        Exit Sub
    End If
    
    Dim i       ' As Long
    Dim count   ' As Long
    count = containerColl.count
    For i = 0 To count - 1
        Set containerObject = containerColl.Item(i)
        If Checkerror("ContainerCollection.Item") = True Then
            Exit Sub
        End If
        
        If (containerObject.Name = containerName) Then
            Exit For
        Else
            Set containerObject = Nothing
        End If
    Next 
    
    If not (containerObject Is Nothing) Then
        '----
        ' Run the Container
        '----
        containerObject.Run
        If Checkerror("Container.Run") = True Then
            Exit Sub
        End If               
    End If
                
    '-----
    ' Save the new project
    '-----
    prjObject.Save
    If Checkerror("Project.Save") = True Then
        Exit Sub
    End If
    
    '-----
    ' Close the project
    '-----
    prjObject.Close
    If Checkerror("Project.Close") = True Then
        Exit Sub
    End If
       
End Sub

Function Checkerror(fnName)
    Checkerror = False
    
    Dim strmsg      ' As String
    Dim errNum      ' As Long
    
    If Err.Number &amp;lt;&amp;gt; 0 Then
        strmsg = "Error #" &amp;amp; Hex(Err.Number) &amp;amp; vbCrLf &amp;amp; "In Function " &amp;amp; fnName &amp;amp; vbCrLf &amp;amp; Err.Description
        'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.
        Checkerror = True
    End If
         
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I looked around but having trouble doing it myself.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 16:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953253#M45609</guid>
      <dc:creator>sbkp</dc:creator>
      <dc:date>2024-12-11T16:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help to Convert VBS Script to Powershell for SAS EG Project file with Specific Container</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953260#M45610</link>
      <description>&lt;P&gt;As of yet, I have not seen anything that will convert easily between VB* and any of the .NET world (including PowerShell).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best bet, in my experience, is to ask ChatGPT to do the prelim conversion. I then tweak it from there. It is mostly ok but is never right. YMMV. You have a trivial script so easy to convert.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VBS is dead so best to move away. PowerShell is an excellent choice.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 17:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953260#M45610</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2024-12-11T17:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help to Convert VBS Script to Powershell for SAS EG Project file with Specific Container</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953394#M45612</link>
      <description>&lt;P&gt;VB Script had its days (or decades) but it is on the way out. Here's a PowerShell script (I named it &lt;STRONG&gt;RunFlow.ps1&lt;/STRONG&gt;) that can take a project (full path) and flow name and run it. It also Saves the project file after running the flow (which will update any project results like log, ODS, etc).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="shell"&gt;# check for an input file
if ($args.Count -eq 2)
{
  $fileToProcess = $args[0] 
  $flowToRun = $args[1]
}
else
{
  Write-Host "EXAMPLE Usage: RunFlow.ps1 path-and-name-EGP-file process-flow"
  Exit -1
}

# check that the input file exists
if (-not (Test-Path $fileToProcess))
{
  Write-Host "$fileToProcess does not exist."
  Exit -1
}

# change this if running a different version of EG
$egVersion = "SASEGObjectModel.Application.8.1" 

# create an instance of the EG automation model
$eguideApp = New-Object -comObject $egVersion
Write-Host $eguideApp.Name  $eguideApp.Version
Write-Host "Opening " $fileToProcess ", looking to run " $flowToRun

$project = $eguideApp.Open("$fileToProcess", "")

# Show all of the process flows in the project
$pfCollection = $project.ContainerCollection
foreach ($pf in $pfCollection)
{
	  if ($pf.ContainerType -eq 0)
	  {
		if ($pf.Name -eq $flowToRun)
        {
          Write-Host "Running " $flowToRun
          $pf.Run()
          Write-Host "Saving updated " $project.Name
          $project.Save()
        }        
      }

}

$project.Close()

# Quit (end) the application object
$eguideApp.Quit()&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;You run it like this:&lt;/P&gt;
&lt;LI-CODE lang="shell"&gt;.\RunFlow.ps1 "C:\Projects\Automation\Daily_Job.egp" "Prod Flow"

Enterprise Guide 8.5.0.0
Opening  C:\Projects\Automation\Daily_Job.egp , looking to run  Prod Flow
Running  Prod Flow
Saving updated  Daily_Job&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can definitely use more error checks for a more robust script. See&amp;nbsp;&lt;LI-MESSAGE title="Doing More with SAS Enterprise Guide Automation" uid="417832" url="https://communities.sas.com/t5/SAS-Communities-Library/Doing-More-with-SAS-Enterprise-Guide-Automation/m-p/417832#U417832" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;for more information about the EG automation model.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 15:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Help-to-Convert-VBS-Script-to-Powershell-for-SAS-EG-Project-file/m-p/953394#M45612</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2024-12-12T15:17:56Z</dc:date>
    </item>
  </channel>
</rss>

