I have two variables (a simple string - where $strVMPrepDir = 'PrepareSQL' and an array $SQLParameters = an array I imported in from excel
SQLParameters = Import-Excel -Path $DataSourcePath -WorksheetName 'SQL'
where the array looks like
@{AGTSVCPASSWORD=password; ISSVCPASSWORD=password; ASSVCPASSWORD=password; SQLSVCPASSWORD=password; RSSVCPASSWORD=password; SAP
WD=password}
Or in its native form
$SQLParameters.AGTSVCPASSWORD = password
$SQLParameters.ISSVCPASSWORD=password
etc
etc
I am trying to pass these variable over to the VM with Invoke-Command with the following
$InstallSQL = {
$copyFileLocation = "C:\$args[0]\ConfigurationFile.ini"
$SQLConfigurationINI = "C:\$args[0]\ConfigurationFile2.ini"
$errorOutputFile = "C:\$args[0]\ErrorOutput.txt"
$standardOutputFile = "C:\$args[0]\StandardOutput.txt"
Write-Host "Getting the name of the current user to replace in the copy ini file." -ForegroundColor Green
$user = "$env:UserDomain\$env:USERNAME"
Write-Host "Update credential information to SQL Configuration file" -ForegroundColor Green
#$replaceText = (Get-Content -path $copyFileLocation -Raw) -replace "##MyUser##", $user
#Set-Content $copyFileLocation $replaceText
Get-Content $copyFileLocation | ForEach-Object { $_ `
-replace '<!--REPLACE WITH SQL AGENT PASSWORD-->',"$args[1].AGTSVCPASSWORD" `
-replace '<!--REPLACE WITH INTEGRATION SERVICES PASSWORD-->',"$args[1].ISSVCPASSWORD" `
-replace '<!--REPLACE WITH ANALYSIS SERVICES PASSWORD-->',"$args[1].ASSVCPASSWORD" `
-replace '<!--REPLACE WITH SQL SERVICES PASSWORD-->',"$args[1].SQLSVCPASSWORD" `
-replace '<!--REPLACE WITH SQL SA PASSWORD-->',"$args[1].SAPWD" `
-replace '<!--REPLACE WITH REPORTING SERVICES PASSWORD-->',"$args[1].RSSVCPASSWORD" `
} | Set-Content $SQLConfigurationINI
Push-Location -Path R:\
write-host $SQLConfigurationINI
.\Setup.exe /ConfigurationFile=$SQLConfigurationINI
# Configure inbound firewall rule for SQL Write-Host "Update Windows Firewall for inbound SQL..." -ForegroundColor Green New-NetFirewallRule -DisplayName "MSSQL ENGINE TCP" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow
}
Invoke-Command -ComputerName $strVMName -ScriptBlock $InstallSQL -Credential $DCLocalCredential -ArgumentList $strVMPrepDir,$SQLParameters
Except the output is not what I expect, for example
$copyFileLocation = "C:\$args[0]\ConfigurationFile.ini", I was expecting this
$copyFileLocation = "C:\PrepareSQL\ConfigurationFile.ini" but I am getting this instead
$copyFileLocation = "C:\PrepareSQL [0]\ConfigurationFile.ini" (with a space after the L)
Also, my output for "$args[1].AGTSVCPASSWORD", I was expecting this
password, but I am getting this as output instead
[1].AGTSVCPASSWORD
I have used the $args with invoke-command before, but only for a single simple string (e.g. -ArgumentList $strVMPrepDir) and never try it as 2 strings, nor an array before. Is this possible, or just my syntax is off?