VMware Cloud Community
Grizzled_1
Contributor
Contributor

Edit files in ESXi via PowerCLI

Greetings, 

I need to edit two files in every ESXi host we have (hundreds). Is there a PowerCLI cmdlet to edit files?  I've looked and cannot find such a thing. If not, does anyone have a suggestion how to do this without logging into every host?  What I need to change is the following:

A. Edit /etc/vmware/logfilters and add the following lines:

          5 | storageRM | .*

          5 | sdrsInjector | .*

B. Edit /etc/vmsyslog.conf and add the following line:

          enable_logfilters = true

C. Run command: "esxcli system syslog reload" for the configuration to take effect.

0 Kudos
6 Replies
LucD
Leadership
Leadership

Are you allowed to enable/start SSH on the ESXi nodes?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Grizzled_1
Contributor
Contributor

We are, yes. I even use a script I wrote to enable/disable SSH via PowerCLI to manage that, since Security doesn't want to SSH open unless we're actively using it. 

Tags (1)
0 Kudos
LucD
Leadership
Leadership

Then you could use the Posh-SSH module to run a sed command on the ESXi node.
See for example Solved: Re: Need to alter a /etc/pam.d/password file but w... - VMware Technology Network VMTN


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Grizzled_1
Contributor
Contributor

Thank you. Is there another way you can share the example from https://www.lucd.info/knowledge-base/use-posh-ssh-instead-of-putty/ ?  That site is being blocked by our proxy. I've asked for permission to whitelist it but that may take a while, or it won't be approved at all. 

0 Kudos
LucD
Leadership
Leadership

Sure, it is just a short example
putty.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Grizzled_1
Contributor
Contributor

Thank you very much. I am trying to write the script to login to each host in a for loop and edit those two files. I am struggling but I think you have provided a way for me to be successful. I'm just not there yet. 

0 Kudos