I have an Ubuntu 18.06 VM with 2 network adapters connected, one internal and one external. However, I would like set the adapters which is using the internal switch "NATSwitch" to have a static MAC address while the other can have a dynamic one.
PS C:\> Get-VMNetworkAdapter -VMName "Docker_1806"
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
Network Adapter False Docker_1806 Robot Switch 001122334455 {Ok} {169.254.74.100, fe80::215:5dff:feb2:1188}
Network Adapter False Docker_1806 NATSwitch 554433221100 {Ok} {192.168.137.100, fe80::a00:3cff:fea3:4209}
I have tried using this command:
PS C:\> Set-VMNetworkAdapter -VMName "Docker_1806" -StaticMacAddress "01-02-03-04-05"
But that seemed to have changed both of my adapter's MAC address to static.
I've tried:
PS C:\> $vmadapter = Get-VMNetworkAdapter -VMName "Docker_1806"
PS C:\> $vmadapter[1]
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
Network Adapter False Docker_1806 NATSwitch 554433221100 {Ok} {192.168.137.100, fe80::a00:3cff:fea3:4209}
PS C:\> Set-VMNetworkAdapter -VMName "Docker_1806" -VMNetworkAdapter $vmadapter[1] -StaticMacAddress "01-02-03-04-05"
Set-VMNetworkAdapter : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ set-vmnetworkadapter -vmname "Docker_V2_Dev" -VMNetworkAdapter $vmada ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VMNetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.HyperV.PowerShell.Commands.SetVMNetworkAdapter
Is there a way to change only one of them through Powershell on the host? I can't seem to find a way to set static MAC for a specific adapter for that VM.
On another note, the network configurations for this VM is set using netplan configurations inside the VM so that it can have static IP addresses.
Thanks in advance!
You should choose which of parameters sets you would like to use - searchinf by VMName or VMNetworkAdapter object.
More information about different parameter sets you could find in the doc:
https://learn.microsoft.com/en-us/powershell/module/hyper-v/set-vmnetworkadapter?view=win10-ps
$vmadapter = Get-VMNetworkAdapter -VMName "Docker_1806"
Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[1] -StaticMacAddress "01-02-03-04-05"
This one worked for me.
Change MAC address (Properties->Configure...->Network Address) in Default switch properties. In my case i see incorrectly set MAC address with dashes (maybe set while default Hyper-V installation).
Related
I am trying to get network mapped drives using below commands.
Get-WmiObject -Class Win32_MappedLogicalDisk | %{$_.Name}
Get-WmiObject -Class Win32_MappedLogicalDisk | %{$_.ProviderName}
This works in some system however does not in other systems(may be powershell version issue) So I thought of using net use command. However, I am unable to fetch the values or not sure how to get the values displays when i type 'net use'
when I type net use I get status, Local, Remote and Network column. I tried to use the below command to get the field values.
net use | select local.
but I get blank or nothing
Used below command.
net use | select local.
Need to get Local and Remote values from net use command.
See this for parsing legacy console output ---
How to Convert Text Output of a Legacy Console Application to PowerShell Objects
Yet, along with what LotPings gave you already. Your query could be a duplicate of this ...
Equivalent of net use (to list computer's connections) in powershell?
... and it's accepted answer
# For the mapped logical drive you can use WMI class Win32_MappedLogicalDisk :
Get-WmiObject Win32_MappedLogicalDisk
# Here is another way with Win32_LogicalDisk :
PS C:\> Get-WmiObject -Query "Select * From Win32_LogicalDisk Where DriveType = 4"
DeviceID : V:
DriveType : 4
ProviderName : \\jpbdellf1\c$
FreeSpace :
Size :
VolumeName :
# Edited
# You are right, you can get what you need with Win32_NetworkConnection :
Get-WmiObject Win32_NetworkConnection
LocalName RemoteName ConnectionState Status
--------- ---------- --------------- ------
\\jpbasusf1\temp Connected OK
# On Seven or W2K8 be careful to call this with the same user that run the NET USE because it's a session information.
How about using get-psdrive (the root header actually matches the displayroot property)?
get-psdrive | where displayroot -like '\\*'
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
Y 91.84 7.82 FileSystem \\server....
Depending on the PowerShell versions available you might encounter similar problems with
Get-SmbMapping which wraps the CimClass: ROOT/Microsoft/Windows/SMB:MSFT_SmbMapping.
But has otherwise an output resembling net use.
To process the real net use output and convert to an object with properties,
you may use:
$SmbMapping = (net use) -like '* \\*' | ForEach-Object {
$Status,$Local,$Remote,$Null = $_ -split ' +',4
[PSCustomObject]#{
Status = $Status
Local = $Local
Remote = $Remote
}
}
This works at least in my German locale Win10.
(Not sure about different status messages in other locales.)
I'm creating a script that gets all vm's and shows the DiskSpace. THe Problem is, that if a vm is powered off, it won't show the uesed Space of a disk.
Here are two examples: First one with an VM that is powered on:
PowerCLI C:\> Get-VM sluwv0039
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
sluwv0039 PoweredOn 2 4.000
PowerCLI C:\> $VM = Get-VM sluwv0039
PowerCLI C:\> $VM.guest.disks
CapacityGB FreeSpaceGB Path
---------- ----------- ----
49.997 5.417 C:\
Example two where the VM is powered off:
PowerCLI C:\> Get-VM sluwv0012
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
sluwv0012 PoweredOff 4 8.000
PowerCLI C:\> $VM = Get-VM sluwv0012
PowerCLI C:\> $VM.guest.disks
PowerCLI C:\>
Note: The Last line is the output. There is no "CapacityGB" etc.
Correct, that property is reading from the guest file system to see how much space is left on the partition. In your case, the C:\ drive. If the VM is off, there's no way for PowerCLI to find that property.
Alternatively, you could look at the $vm.ExtensionData.Summary.Storage properties and do some rough conversions. Note: the output of those are in byte, so you'll want to convert them to GB. Example: $tempVM.ExtensionData.Summary.Storage.Committed / 1GB
It won't be exact, but it will be better than no output at all.
here is example of script to show vm specification:
Get-Vm | Select-Object Name,PowerState,VMHost,NumCPU,MemoryGB,ProvisionedSpaceGB,#{N="HostName";E={#($.guest.HostName)}},#{N="Gateway";E={#($.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress[0])}},#{N="DNS";E={$.ExtensionData.Guest.IpStack.DnsConfig.IpAddress}},#{N="IPAddress";E={#($.guest.IPAddress -like "192.168.*")}},#{N="Nics";E={#($.guest.Nics)}},#{N="Datastore";E={#($ | Get-DataStore)}},#{N="Disks";E={#($.guest.Disks)}},Version,#{N="State";E={#($.guest.State)}},#{N="OS";E={#($_.guest.OSFullName)}}
the sample output is like this:
Name State VMHost NumCpu MemoryGB PowerState ProvisionedSpaceGB Version IPAddress HostName OS Nics Disks VMwareTools Gateway DNS
test Running 192.168.32.100 2 1 PoweredOn 43.1085147 v8 192.168.122.1 Elenoon Ubuntu Linux (64-bit) Network adapter 1:VM Network Network adapter 2:local : : Capacity:17167286272, FreeSpace:14212493312, Path:/ Capacity:15188623360, FreeSpace:15154872320, Path:/media/files Capacity:10724835328, FreeSpace:10672824320, Path:/var/log Capacity:973770752, FreeSpace:690139136, Path:/boot guestToolsRunning 127.0.0.1
hope to be useful ;)
By using the cmdlet Get-AzureRmVM I show a list of VMs in an Azure subscription. Then by using a keyboard user input like (1,2,3..) I want to store into variables the name and the resource group name of the selected VM
Get-AzureRmVM
ResourceGroupName Name Location VmSize OsType NIC Provision
ingState
----------------- ---- -------- ------ ------ --- ---------
NW-TRAINING VM1 westeurope Standard_D2s_v3 Windows vm1518 Succeeded
NW-TRAINING VM2 westeurope Standard_D2s_v3 Windows vm2357 Succeeded
TESTDNS machine1 westeurope Standard_DS1_v2 Linux machine1813 Succeeded
All you have to do is to assign the result of the Get-AzureRmVm to a variable and then you can access the specific VM using the index. e. g.:
$vms = Get-AzureRmVm
$index = Read-Host "Please enter the VM index"
$vms[$index] | Select-Object Name, ResourceGroupName
I have been trying to get the VM OS name from Microsoft Azure using PowerShell.
I think I am very close to the solution but I don't know where I'm going wrong.
This is the command that I am using to get the VM details:
Get-AzureRmVM -ResourceGroupName TEST -Name VF-Test1 | Select OsType
The answer I get is just blank.
When running the following command:
Get-AzureRmVM -ResourceGroupName TEST -Name VF-Test1
I get all the details that belong to that VM.
The osType property lives inside $_.StorageProfile.osDisk
Get-AzureRmVM -ResourceGroupName TEST -Name VMNAME |
Format-Table Name, #{l='osType';e={$_.StorageProfile.osDisk.osType}}
Name osType
------ ------
VMNAME Windows
Use https://resources.azure.com to explore the object representation when in doubt, or pipe to Show-Object, like i did below.
You can get resource groups' VMs by Get-AzureRmVM and classic VMs by Get-AzureVM. Both of the returning values of the two cmdlets contain OS type properties but in different paths.
For the cmdlet Get-AzureRmVM, the OS type property path is $vm.StorageProfile.OsDisk.OsType
For the cmdlet Get-AzureVM, the OS type property path is $vm.VM.OSVirtualHardDisk.OS
There exists a sample code about fetching Azure VM OS Type here: https://gallery.technet.microsoft.com/How-to-retrieve-Azure-5a3d3751
Get-AzVM -name SERVERNAME | select name, #{n="OS";E={$_.StorageProfile.OsDisk.OsType}}, #{n="Offer";E={$_.StorageProfile.ImageReference.offer}} , #{n="SKU";E={$_.StorageProfile.ImageReference.sku}}, #{n="Publisher";E={$_.StorageProfile.ImageReference.Publisher}}
RESULT:
I am trying to use Get-PrintConfiguration on a networked printer but for some reason it returns this error
Get-PrintConfiguration : The specified printer was not found. At
line:1 char:1
+ Get-PrintConfiguration -PrinterName "Printer1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration)
[Get-PrintConfiguration], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070709,Get-PrintConfiguration
Is there something I am missing? The Printer name is correct and im somewhat confident the syntax is correct.
Edit:
I just noticed the second line. If you're specifying a printer name by concatenating multiple strings, be sure to surround the concatenations with parenthese. Example:
Get-PrinterConfiguration -PrinterName ("Printer1" + "-PC1")
Hope some of this helps.
Original:
Only posting this as an answer since I don't have enough reputation to make a comment, but in order to get a proper answer, could you provide more details, please? Perhaps a code/script example?
This worked for me to get a network printer configuration
Get-Printer | Where-Object -Property 'Name' -EQ 'Sharp MX-4140N' | Get-PrintConfiguration
PrinterName ComputerName Collate Color DuplexingMode
----------- ------------ ------- ----- -------------
Sharp MX-4140N True True OneSided
Note: computer name blanked intentionally.