0

Can I pass a VBA variable into a called Powershell script?.

With the help of the above post, I am able to pass one variable to PowerShell. I need to pass two variables, there I failed with the below script. Can someone please help me with it.

strCommand = "powershell -ExecutionPolicy Unrestricted  -file `\""C:\Users\n3540551\Desktop\cluster\remote.ps1`\"" -name `\""" & nameVariable & "`\"" -pass2 `\""" & passVariable & "`\"""

PowerShell script as below:-

param([string]$name)
param([string]$pass2)
$MyUserName = "cctv";
$MyPassword = ConvertTo-SecureString $pass2 -asplaintext -force;
$MyCredentials2 = new-object -typename System.Management.Automation.PSCredential `
-argumentlist $MyUserName,$MyPassword

$scriptblock = {if ((Select-String -Path "C:\ProgramData\Root.1.log" -Pattern "Mismatching SRP verifier") -ne $null){echo "Mismatching SRP verifier found. Please check File"}else{ echo "All Goood!"}}

 Invoke-Command -ComputerName $name -credential $MyCredentials2 -ScriptBlock $scriptblock
colorstt
  • 3
  • 3

1 Answers1

0

The PowerShell parser only recognizes 1 param statement per block, so you need to change:

param([string]$name)
param([string]$pass2)

to

param(
  [string]$name,
  [string]$pass2
)
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206