Is it possible to locate a SCVMM Management server from within a Hyper-v host? Is this possible via powershell? I am trying to find which machine manages one of my Hyper-v hosts. I've had no luck searching through registry/wmi. Any ideas?
Thanks in advance!
Not sure about powershell, but I just had to do this today.
1) looked up the port config for scvmm. So far, 5985 looks like the one: Link
2) On your host, run netstat -ano |find "5985"
3) That should return a list scvmm management servers connected.
As far as I know, no. What you could do is to query all of your SCVMM servers and see which happens to know the guest.
Load up the VMM module and connect to your VMM.
# VM name, might or might not be hostname
$guestToLook = "myLostVM"
# A list of all of your VMM servers
$VMMServers = #("vmmsrv01", "vmmsrv02", "vmmsrv03")
$VMMServers | % {
# Connect to VMM server
Get-VMMServer $_
# Get a VM from the VMM host by guest name
$vm = Get-VM -name $myLostVM
# If VM object is returned, you got the VM from current VMM host.
if($vm.Name -eq $myLostVM) { "{0} is managed by VMM host: {1}" -f $vm.Name, $_}
}
Here's a solution via PowerShell.
First we need the registry path on the host for SCVMM config values.
$scvmmAgentKeys = 'HKLM:\SOFTWARE\Microsoft\Microsoft System Center Virtual Machine Manager Agent\Setup'
Now we grab the SCVMM agent port from the registry path.
$wsManTcpPort = (Get-ItemProperty -Path $scvmmAgentKeys -Name WSManTcpPort).WSManTcpPort
Finally, collect the addresses which are listening on that port.
$scvmmAddress = (Get-NetTCPConnection -LocalPort $wsManTcpPort).LocalAddress | Get-Unique | where { $_ -ne "::" }
Note that if anything else has a connection established on the same port (default port at time of writing is 5985) then $scvmmAddress will be an array including the addresses of those other established connections, which are not necessarily SCVMMs.
Fantastic . The only correction shall be
3. $scvmmAddress = (Get-NetTCPConnection -LocalPort $wsManTcpPort).**Remoteaddress** | Get-Unique | where { $_ -ne "::" }
Related
Get-WindowsOptionalFeature –Online –FeatureName SMB1Protocol
Will tell me if the machine I run it on is running smbv1
Can this be somehow modified to run on remote machines? I have about 1000 servers, 6000 workstations, and 10,000+ IoT/Network devices (though, they're not running windows).
I know packet capturing is the typical method, however I don't really have a central choke-point to put a packet analyzer in my environment.
I solved this with nmap + powershell
$NmapFolder = Get-ChildItem -Path "U:\nmap reports\Nmap Subnet
Scans\September2019" -Recurse -Directory -Force -ErrorAction SilentlyContinue
$data = ForEach ($item in $NmapFolder){
$Subnet = $item.Name.replace('_','/')
write-host "scanning"$Subnet". Please wait..."
nmap -p 445 --script smb-protocols -oN "U:\\nmap reports\\Nmap Subnet Scans\\September2019\\$item\\SMB_results.nmap" $Subnet
write-host "Done, report written for"$Subnet". Report has been written to: U:\\nmap reports\\Nmap Subnet Scans\\September2019\\"$item"\\SMB_results.nmap"
}
I made a folder (September2019) that contains a bunch of folders named after my subnets:
10.0.0.0_23
10.10.10.0_24
10.100.10.0_24
etc. I have a bout 120 local subnets in my organization.
I then change _ to / (Windows folder names can't have /)
Now I have a CIDR notation that I can throw at nmap.
Nmap has a script to analyze a target for SMB, and it'll tell me what versions it's running.
The output for the whole subnet goes into it's respective folder, and move to the next.
I'll write another script to parse all of the results and only show me targets that have SMB1 enabled.
I have few vm's deployed inside an esxi,whose details I can find out using "Get-Vm"
command,now I want to enable ssh for these all vm's ,but unable to do so.I am aware
of command to enable ssh for host/esxi like:
"Get-VMHost | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}"
But cant figure out a way to enable ssh for the vm's inside a esxi,any pointers will be appreciated.
The command you're referencing is for controlling the ESXi Host's SSH service and has no bearing on the guest VM's SSH status.
To enable SSH on those guests will require a couple things, namely VMware Tools installed and running as well as some valid credentials to the guest OS.
Once you have those, you can use the Invoke-VMScript cmdlet to send commands to the VM through VMware Tools.
Example:
Invoke-VMScript -VM vmName -ScriptType Bash -ScriptText "systemctl start sshd.service" -GuestUser username -GuestPassword password
As seen in the many Azure Quick Start examples, it is common to use Get-NetAdapter to get the Network Interface Name for things like DNS configuration. This is an example:
configuration MyConfig
{
$Interface=Get-NetAdapter|Where Name -Like "Ethernet*"|Select-Object -First 1
$InterfaceAlias=$($Interface.Name)
Node localhost
{
xDnsServerAddress DnsServerAddress
{
Address = $DNSServer
InterfaceAlias = $InterfaceAlias
AddressFamily = 'IPv4'
}
}
}
If the command Get-NetAdapter is in my configuration and the config is compiled by Azure Automation, I get the following error:
Cannot connect to CIM server. The specified service does not exist as an installed service.
Is there a workaround?
The answer is - its not possible. The configs are compiled on the Azure Automation server, not the target node. Even if I were to find a way to get the network adapter name in the config, it would get the name of the adapter on the DSC pull server, not the target node.
The code in the question will work if you use 1 config per node and you are pre-compiling on the target node then uploading it to Azure Automation.
Try this:
xDnsServerAddress DnsServerAddress
{
Address = $DNSServer
InterfaceAlias = (Get-NetAdapter | ? name -Like "Ethernet*" | select -First 1).Name
AddressFamily = 'IPv4'
}
Get-NetAdapter internally is using WMI to get the information which doesn't work in Azure Automation. However you can use get-netipinterface cmdlet to get information about the adapter.
What do you all recommend using as a replacement for dnsmasq on Windows on AppVeyor? Do you have any installation instructions for a replacement or an example job I can look at?
I believe it is pretty easy to script installation (using Install-WindowsFeature) and configuration of standard MS DNS and DHCP on Appveyor VM and configure them with PowerShell.
Here are useful PowerShell commands:
https://technet.microsoft.com/en-us/library/jj590751(v=wps.630).aspx
https://technet.microsoft.com/en-us/library/jj649850.aspx
Here is sample install section for Appveyor.yml:
install:
- ps: |
Install-WindowsFeature -Name DNS -IncludeManagementTools -WarningAction SilentlyContinue
Install-WindowsFeature -Name DHCP -IncludeManagementTools -WarningAction SilentlyContinue
Add-DnsServerPrimaryZone -Name foo.bar -ZoneFile foo.bar.dns
Add-DhcpServerv4Scope -Name TestScope -StartRange 192.168.1.100 -EndRange 192.168.1.110 -SubnetMask 255.255.255.0
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like '*ethernet*'}).IPAddress
Set-DHCPServerv4OptionValue -DnsDomain foo.bar -DnsServer $ip
However, I am not sure I fully understand the scenario. What machines are going to be clients of those services? Appveyor build is being executed on the single VM, which is behind the NAT and it is not accessible from public Internet. Or it will be some pieces of your software who will connect to local machine’s DNS/DHCP server, acquire private IP and register some name?
Also please note that you can configure hosts file, which may be simpler solution for your problem.
Thank you,
Ilya.
I'm going through a scenario where i boot a Newly built VM with a sysprepped vhd attached, once the setup process completes with installing devices etc and the OS gets loaded i wanted to wait till this entire process finishes and the VM is assigned an IP address via DHCP.
PS C:\Users\Administrator> Start-VM -Name dv.VMWIN2K8R2-3.Hng
PS C:\Users\Administrator> while ((Get-VM -Name dv.VMWIN2K8R2-3.Hng | select -ExpandProperty networkadapters).ipaddress[0] -match $null)
{
Start-Sleep 3
Write-Host "Waiting to Acquire IP Address" -ForegroundColor green
}
$ipaddress=(Get-VM -Name dv.VMWIN2K8R2-2.Hng | select -ExpandProperty networkadapters).ipaddresses[0]
Write-Host "VM has acquired an IPAddress of $ipaddress"
I Tried the above snippet but the while loop never run's, i have noticed that while VM is shutdown the ip address parameter is blank so i thought to match it till it shows Null and when i boot up the VM and once the server gets an IP address by DHCP it should exit the while loop and print the IP address on console.
The IP is probably not null, so it's doing exactly what it should. The IP is probably 169.254.x.x, or at least that's what happens to me before I pick up DHCP. How about choosing the first octet of the address it should have after it picks up an address and using that?
EDIT: Maybe it's not 169 as I thought, after re-reading your post. My advice still applies. Try using something like this: While (!($ip -like "10.*")
If there is no network stack there are no addresses and I think you'll find the array is not there. Chris is on the right track. I think you'll need to not do what you're doing but first test to see if ipaddress is a property, is an array, and has at least 1 item in it before checking the value of that item.
Hi Guys i was able to solve the issue, i used the Get-VMNetworkAdapter Cmdlet and it solved the issue
while (((Get-VMNetworkAdapter $vmname | select -ExpandProperty ipaddresses) -eq $null -or ((Get-VMNetworkAdapter $vmname | select -ExpandProperty ipaddresses) -match "169.")))
{
Write-Progress -Activity "Waiting for VM to Aquire an IPAddress"
}