用Start-Process和ArgumentList替换Powershell变量

问题描述 投票:0回答:1

我有一些powershell代码,它可以获取FQDN并将其保存到变量中……效果很好:

$FQDN=(Get-WmiObject win32_computersystem).DNSHostName.ToLower()+"."+(Get-WmiObject win32_computersystem).Domain

LogWrite“ [+]已将系统标准主机名检测为:$ FQDN”

但是,当我插入FQDN变量的字符串时,我无法使其正常工作。我已经尝试了滴答,双引号和单引号,但均未成功:

Start-Process -Wait $OUTPATH64 -ArgumentList '/s /v"/qn INSTALLDIR=\"C:\Program Files\IBM\WinCollect\" LOG_SOURCE_AUTO_CREATION_ENABLED=TRUE LOG_SOURCE_AUTO_CREATION_PARAMETERS=""Component1.AgentDevice=DeviceWindowsLog&Component1.Action=create&Component1.LogSourceName=REPLACEME&Component1.LogSourceIdentifier=REPLACEME&Component1.Dest.Name=test.domain.com&Component1.Dest.Hostname=test.domain.com&Component1.Dest.Port=514&Component1.Dest.Protocol=TCP&Component1.Log.Security=true&Component1.Log.System=true&Component1.Log.Application=true&Component1.Log.DNS+Server=false&Component1.Log.File+Replication+Service=false&Component1.Log.Directory+Service=false&Component1.RemoteMachinePollInterval=3000&Component1.EventRateTuningProfile=Default+(Endpoint)&Component1.MinLogsToProcessPerPass=100&Component1.MaxLogsToProcessPerPass=150"""'

在您看到“ REPLACEME”字符串的地方,我需要将其替换为$ FQDN变量字符串。每当我使用反引号$FQDN或双引号“ $ FQDN”甚至单引号“ $ FQDN”时,我都会得到文字字符串“ $ FQDN”,并且代码段实际上并未进行变量替换。

我在这里想念什么?我什至还尝试了反引号双引号"$FQDN"。我希望将REPLACEME字符串替换为实际的主机名+域,例如hostname.domain.com或$ FQDN变量中设置的内容。 ArgumentList引号需要保持不变,因为我只能通过以Ar开头的'到'“”结束的方式引用ArgumentList来使我的命令正常工作。我们将不胜感激。

我拥有一些Powershell代码,它可以获取FQDN并将其保存到变量...效果很好:$ FQDN =(Get-WmiObject win32_computersystem).DNSHostName.ToLower()+“。” +(Get-WmiObject。 ..

powershell variables quotes
1个回答
0
投票

[单]]-引号中的字符串('...')是PowerShell中的verbatim

© www.soinside.com 2019 - 2024. All rights reserved.