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
4
  • What does your powershell script look like? We’d have to guess to help. Commented Jan 6, 2022 at 5:37
  • @DougMaurer PowerShell script as above Commented Jan 6, 2022 at 5:51
  • what's all the `\ you have in the call? Commented Jan 6, 2022 at 7:46
  • You only need one param block. Param([string]$name,[string]$pass2) Commented Jan 6, 2022 at 9:43

1 Answer 1

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
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. that was the perfect fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.