Trying to automate some of our processes and we need to run some SAS processes from command line. Since we are running our code from SAS Server, we need to use PowerShell. I have created a script than can successfully connect to the server, but I am not able to invoke the the stored procedure. The methods for C# or VB don't always translate exactly, so I'm having an issue trouble shooting. ================================================================== # create the Integration Technologies objects $objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2 $objServerDef = New-Object -ComObject SASObjectManager.ServerDef $objServerDef.MachineDNSName = "<<SERVERNAME>>" # SAS Workspace node $objServerDef.Port = 8561 # workspace server port $objServerDef.Protocol = 2 # 2 = IOM protocol # Class Identifier for SAS Workspace (or some other ID) $objServerDef.ClassIdentifier = "<<CLASSID>> " try { # create and connect to the SAS session $objSAS = $objFactory.CreateObjectByServer( "SASApp", # server name $true, $objServerDef, # built server definition "", # user ID "" # password ) Write-Host "Connected to " $objServerDef.MachineDNSName } catch [system.exception] { Write-Host "Could not connect to SAS session: " $_.Exception.Message } # local directory for downloaded file $localPath = "c:\data" # program to run $program = "proc STP PROGRAM=`"/FOLDER/PROCEDURENAME`"; run;" # run the program $objSAS.LanguageService.Submit($program); $objSAS.Close() ============================================================== I'm getting the following error: You cannot call a method on a null-valued expression. At F:\Testautomate.ps1:44 char:1 + $objSAS.LanguageService.Submit($program); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Let me know if there is a better way or if I'm missing something here.
... View more