WMIC command for dhcp config win server 2003 - wmi

I want to remotely config some services like dhcp and dns on windows server 2003 using wmic.
For this goal I using java and connect to wmic on windows server 2003 but I don't know how can I config dhcp via wmic in Windows Server 2003.
What's the command for this purpose?
Thanks in advance

Not sure about Java, but you could do powershell commands with WMIC. If you have Windows Server 2003 SP2 you should be able to install PowerShell 2.
The command you need is:Get-WMIObject Win32_NetworkAdapterConfiguration
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername . |
where{$_.IPEnabled -eq $true -and $_.DHCPEnabled -eq $true}
Foreach($NIC in $NICs) {
$ip = ($NIC.IPAddress[0])
$gateway = $NIC.DefaultIPGateway
$subnet = $NIC.IPSubnet[0]
$dns = $NIC.DNSServerSearchOrder
$NIC.EnableStatic($ip, $subnet)
$NIC.SetGateways($gateway)
$NIC.SetDNSServerSearchOrder($dns)
$NIC.SetDynamicDNSRegistration(“FALSE”)
}
Here is M$ reference for the class:
https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx

Related

Could not connect to TCP port: Connection refused when trying to open Expo app on Android Emulator in WSL2

I've been following this guide https://medium.com/#pellea/using-adb-with-wsl2-7aebbb070a47 and so far have gotten to the point where WSL2 can see the emulator(s) running on Windows through Android Studios -> AVD manager. For example, on both Windows and WSL2, adb devices correctly shows:
List of devices attached
emulator-5554 device
However, when I go to my expo app and try to launch the Android emulator, I get the following error message:
Couldn't start project on Android: could not connect to TCP port 5554: Connection refused
This is after I've tried the following:
exporting ADB_SERVER_SOCKET=tcp:<MY IP>:5037 in my WSL2 profile(s)
Unblocking WSL2 vEthernet connections from my Windows firewall via (from the above link)
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
I've portforwarded 5554 from Windows to WSL2, as well as 5037 (from 0.0.0.0 to 127.0.0.1):
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'";
$WSL_CLIENT -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
$WSL_CLIENT = $matches[0];
iex "netsh interface portproxy add v4tov4 listenport=5554 listenaddress=127.0.0.1 connectport=5554 connectaddress=$WSL_CLIENT"
The ports are as follows:
netsh interface portproxy show all
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
127.0.0.1 8081 172.25.38.171 8081
0.0.0.0 5037 127.0.0.1 5037
127.0.0.1 5554 172.29.149.0 5554
Just had the same issue with Expo.
Here is what fixed it for me:
Check for a process that uses port 5555 (Terminal)
netstat -ano | findstr 5555
Kill the process using its ID (PowerShell)
Stop-Process -ID [PROCESS_ID] -Force
Then it started working.
I had the exact same problem, but with a different setup (using Expo with the Metro bundler on a Mac). I worked around it by trying different virtual device images. Maybe the same can help you.
The virtual device that works with me so far is the one selected in this screenshot: https://i.stack.imgur.com/CFTJ0.png. The other two in the screenshot have the same problem. I don't really know the actual reason, must be something with port access with those other emulated devices.
Image details:
Name: 4 WVGA (Nexus S) API 29
API: 29
Target: Android 10.0 (Google APIs)
CPU/ABI (x86)
I'm sure other images work as well (or configuring the others somehow), i just haven't tried many more because it takes so long and they're so big.
Did you try to map port 5554 to Windows IP instead? (or localhost). The Android emulator is running on Windows, not WSL2, so the port proxy should be from WSL2 to Windows, not backwards.
Have you already solved it in another manner?

VMWare PowerCli - issue in connecting the remote ESX host - ResourceUnavailable: (:) [Get-VMHost], ViServerConnectionException

I am trying to connect remote ESX host using PowerCli Version 6.5 release1 to get all VMs from Windows 10 system.
while executing connect-VIServer I am not getting any output or errors. But while execute get-VMHost I get below error message. Vsphere client can connect to the ESX host using the same credentials . Please help fix powercli issue.
PS C:\> Connect-VIServer 10.44.6.45
PS C:\> Get-VMHost
Get-VMHost : 1/25/2019 6:51:43 PM Get-VMHost You are not currently connected to any servers. Please connect first
using a Connect cmdlet.
At line:1 char:1
+ Get-VMHost
+ ~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Get-VMHost], ViServerConnectionException
+ FullyQualifiedErrorId : Core_BaseCmdlet_NotConnectedError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost
PS C:\>
Based no your code, I don't believe you're connected to the 10.44.6.45 host. I would expect to see a response with the connected host and the credentials being used to establish that connection whereas your code indicates no response at all.
You may want to attempt the following instead:
$creds = Get-Credential # Note: This will prompt you to enter your credentials
Connect-VIServer -Server 10.44.6.45 -Credential $creds

Why does vmware-cmd need a target host when working with vCenter server?

On Windows systems, using VMware PowerCLI, I can connect to a vCenter server using appropriate credentials:
Connect-VIServer myvcenter.example.com
Once connected, I can run Get-VM to see a list of registered VMs. Note that I need not know names of ESX hosts connected to this vCenter server.
When using vmware-cmd, for the similar -l option, both these options need to be provided:
-H <host>
Specifies an ESX/ESXi host or a vCenter Server system.
-h | --vihost <esx_host>
Specifies a target host if the host specified by -H <host> is a vCenter Server system.
Why is that so?
How to list VMs if one does not know the ESX hosts on this vCenter (without using VMware PowerCLI)? I am trying to get this working over SSH on a GNU+Linux system.
Versions:
vSphere SDK for Perl version: 6.5.0
Script 'vmware-cmd' version: 6.5.0
I simply discarded VMware CLI and started using https://github.com/snobear/ezmomi. After having a config.yml file with only connection related options, I was able to list VMs (without knowing ESX hosts).
vmware-cmd is the legacy way that was provided back in the 3.x days to do CLI tasks directly from the ESX service console.
Since you're using vSphere 6.5, I would look at the new CLI called Datacenter CLI (DCLI) instead: http://pubs.vmware.com/vsphere-6-5/index.jsp?topic=%2Fcom.vmware.dcli.cmdref.doc%2Fintro.html

Getting acces to host VM in a VirtualBox with Puppet

I have an application running in a VirtualBox VM that for testing purposes needs to connect to the host machine. The VM is started with Vagrant and managed by Puppet.
What is the best way to set-up this connection? For example, om my host machine the app runs on port 9200. So from my VM I'd like to go to myhostmachine:9200.
Currently I'm thinking of hacking in a small command that adds hostvm as a entry to /etc/hosts using a simple command like this to figure out my host ip (which is the same as the default route).
/sbin/ip -4 route list 0/0 | grep -m 1 default | awk '/default/ { print $3 }'
And just let Puppet run that every time using the exec functionality. However, I get the feeling there has to be a better way.
The guest OS is Ubuntu 12.04 and the Host is OS-X.
Thanks!
As far as I know, at the moment Vagrant always sets up a natted interface to connect to virtualbox, so I think that the ip of your host machine will always be the 10.0.2.2 address you mentioned. I reckon a puppet host declaration might be easier to manage than running that command each time.
host { 'myhostmachine':
ip => '10.0.2.2',
}
The puppet resource reference for hosts has all the other params you can set too.
I was then able to access the host using myhostmachine:9200

Powershell and Psession

I have a powershell script that pulls in a server list with the following headers. computername,optype,opname. I then loop through and if I have a format of server,service,service name then start/stop the service. If I have a format of server,script,script_path_name then I am trying to use an invoke-command to run that script. However I need somehow establish a remote session ... Here is the error txt that I get.
[c1399] Connecting to remote server c1399 failed with the following error message : The client cannot connect to the destination specified in the
request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management
service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (c1399:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
Here is the current code I am using...
elseif($computer.optype -eq "script")
{
write-host running script $computer.opname on $computer.computername
$Status = Invoke-Command -ComputerName $computer.computername -ScriptBlock { . $computer.opname }
Write-Output "Script execution status for $($computer.name) is $Status" >> C:\Scripts\RMLog.txt
}
Enabled power shell remoting on the server.
To enable PowerShell Remoting, run the following command,
Enable-PSRemoting -Force
Please refer below link for more details
http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/
http://powershelltutorial.net/V2/Powershell-With-TFS
this will solve your issue..