Create a bat file by IEM

I’m trying create a bat file to execute some line commands on servers by fixlet, but the actions has failed how if are executing the line command instead of create the file.

Follow the portion of bat file creation, the errors are at line “winrm set winrm/config/client @{TrustedHosts=”*"}"

// execute
createfile until __Setwinrm
@echo off

winrm quickconfig -q
winrm quickconfig -transport:http
winrm set winrm/config/client @{TrustedHosts=""}
winrm set winrm/config @{MaxTimeoutms=“1800000”}
winrm set winrm/config/winrs @{MaxMemoryPerShellMB=“300”}
winrm set winrm/config/service @{AllowUnencrypted=“true”}
winrm set winrm/config/service/auth @{Basic=“true”}
winrm set winrm/config/client/auth @{Basic=“true”}
winrm set winrm/config/listener?Address=
+Transport=HTTP @{Port=“5985”}
netsh advfirewall firewall set rule name=“Windows Remote Management (HTTP-In)” profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any
net stop winrm
sc config winrm start= auto
net start winrm

:end
__Setwinrm

// execute it…

Hi,

If you look in the client log you’ll probably see a, “Relevance Substitution Error”.

This is because when you use { } in actionscript it’s a relevance substitution – this lets you use relevance to dynamically populate arguments for actionscript.

This means when you try to write: winrm set winrm/config/client @{TrustedHosts="*"}" to a file, it’s actually taking TrustedHosts="*" and trying to run it as relevance.

You’ll have to escape these so that the client doesn’t try to interpret them as relevance.

To fix this you just replace your { with {{:

// execute
createfile until __Setwinrm
@echo off

winrm quickconfig -q
winrm quickconfig -transport:http
winrm set winrm/config/client @{{TrustedHosts="*"}
winrm set winrm/config @{{MaxTimeoutms="1800000"}
winrm set winrm/config/winrs @{{MaxMemoryPerShellMB="300"}
winrm set winrm/config/service @{{AllowUnencrypted="true"}
winrm set winrm/config/service/auth @{{Basic="true"}
winrm set winrm/config/client/auth @{{Basic="true"}
winrm set winrm/config/listener?Address=*+Transport=HTTP @{{Port="5985"}
netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any
net stop winrm
sc config winrm start= auto
net start winrm

:end
__Setwinrm
1 Like