Rename Ethernet Adapter In Docker windowsservercore Image - windows

I'm running a microsoft/windowsservercore container on Windows 10 and trying to rename the network adapter from within the container by any means possible. This would be a simple task via PowerShell with something like the following:
Rename-NetAdapter -Name 'Ethernet 2' -NewName 'WuTangLan'
but that gives the following error:
Rename-NetAdapter : A general error occurred that is not covered by a more specific error code.
At line:1 char:1
+ Rename-NetAdapter -Name 'Ethernet 2' -NewName 'WuTangLan'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_NetAdapter..."3e77a8955741"):ROOT/StandardCimv2/MSFT_NetAdapter) [
Rename-NetAdapter], CimException
+ FullyQualifiedErrorId : HRESULT 0x800106d9,Rename-NetAdapter
Is there any way to rename the network adapter from within the container?

Related

Make a copy of swapfile.sys to new location [File not found error]

In PowerShell, I am trying to make a copy of the Windows swapfile (swapfile.sys)
PS C:\> Copy-Item swapfile.sys -Destination C:\Users\
However, I recieve the error:
Copy-Item : Cannot find path 'C:\swapfile.sys' because it does not exist.
At line:1 char:1
+ Copy-Item swapfile.sys -Destination C:\Users\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\swapfile.sys:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
I can confirm the file exists with attrib *.sys
Perhaps this is due to the fact it is a hidden file, or a type of file that cannot be copied? I want to investigate this file with a HexEditor and was hoping to make a stand-alone copy for this.

remove-netnatstaticmapping : The requested operation is not supported. When trying to remove windows docker container port mappings

I've been pulling my hair out over this one. Somewhere along the line, it seems some old port mappings have been left in my windows server 2016 docker server and it is impossible to remove them. This is the command I'm trying to run and the error:
PS C:\Users\...\Desktop> Get-NetNatStaticMapping | Remove-NetNatStaticMapping
Confirm
Are you sure you want to perform this action?
Performing operation Delete on Target H54d664a6-523c-4452-b137-d66701623488;20;0 PolicyStore Local
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): a
Remove-NetNatStaticMapping : The requested operation is not supported.
At line:1 char:27
+ Get-NetNatStaticMapping | Remove-NetNatStaticMapping
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (MSFT_NetNatStat...b4d01327e;6...):root/StandardCi...atStaticMapping)
[Remove-NetNatStaticMapping], CimException
+ FullyQualifiedErrorId : Windows System Error 50,Remove-NetNatStaticMapping
Remove-NetNatStaticMapping : The requested operation is not supported.
At line:1 char:27
+ Get-NetNatStaticMapping | Remove-NetNatStaticMapping
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (MSFT_NetNatStat...701623488;2...):root/StandardCi...atStaticMapping)
[Remove-NetNatStaticMapping], CimException
+ FullyQualifiedErrorId : Windows System Error 50,Remove-NetNatStaticMapping
The below command shows the two port mappings...
PS C:\Users\...\Desktop> Get-NetNatStaticMapping
StaticMappingID : 20
NatName : H54d664a6-523c-4452-b137-d66701623488
Protocol : TCP
RemoteExternalIPAddressPrefix : 0.0.0.0/0
ExternalIPAddress : 0.0.0.0
ExternalPort : 443
InternalIPAddress : 172.20.95.205
InternalPort : 443
InternalRoutingDomainId : {00000000-0000-0000-0000-000000000000}
Active : False
StaticMappingID : 6
NatName : H68dfe202-0efd-480b-b78a-53ab4d01327e
Protocol : TCP
RemoteExternalIPAddressPrefix : 0.0.0.0/0
ExternalIPAddress : 0.0.0.0
ExternalPort : 443
InternalIPAddress : 172.31.142.210
InternalPort : 443
InternalRoutingDomainId : {00000000-0000-0000-0000-000000000000}
Active : False
I automated the uninstall and reinstall of docker on windows server 2016 and have tried all the usual tricks.
Below are the commands I'm using to uninstall docker on the airgapped server:
docker rm -f $(docker ps --all --quiet)
docker system prune --all --volumes -f
Stop-Service docker -Verbose
Stop-Service hns -Verbose
Get-ContainerNetwork | Remove-ContainerNetwork
Get-NetNat | Remove-NetNat -Confirm:$false
Get-VMSwitch -name nat | Remove-VMSwitch -Confirm:$false
Remove-Item -Path "C:\ProgramData\Docker" -Recurse -Force
Remove-WindowsFeature -Name Containers -Verbose
Remove-WindowsFeature -Name Hyper-V -Verbose
Remove-Item C:\ProgramData\Microsoft\Windows\HNS\hns.data -Force
Even still I'm unable to remove the port mappings, and later when trying to run another docker image with port 443 forwarded to the container, I'm given the error:
failed to create endpoint
container_name on network nat: HNS failed with error : The object already exists.
I'm starting to think my only option is to restore the server to a point in time earlier this week.
Any help is greatly appreciated!
In order to get past the issue...delete the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nsi\{eb004a20-9b1a-11d4-9123-0050047759bc}
After deleting the key, the I would get empty results from the commands:
Get-NetNat
Get-NetNatStaticMapping
For reference the answer came from a discussion on a blog post here:
https://www.thomasmaurer.ch/2016/05/set-up-a-hyper-v-virtual-switch-using-a-nat-network/
In this comment:
i was able to solve the “Invalid Operation”-Error. Actually, the Mircosoft Consultant that i share my office with, was able to track this down ;-)
To remove the NetNat, that i couldn´t remove with the powershell-command, i had to delete the following registry-key:
HKLM\System\CurrentControlSet\Control\NSI{eb004a20-…..7759bc}\6\….
The key was the same on two different machines, so this might be always the same GUID.
After deletion, the NetNat was gone and i was finally able to create a new one. This then worked as expected.
Best regards,
Sebastian

AppxProvisionedPackage commands stuck on PowerShell and return DismInitialize failed

I am trying to install LOB UWP application
I used:
Add-AppxProvisionedPackage -Online -PackagePath "APPX_PATH"
-DependencyPackagePath "DEPENDENCIES"-SkipLicense
It worked for the first time, i even asked one of my colleagues to log in and the app was there.
But, after that, i tried to reinstall it with the same command. But the command refused to execute, it's just blinking and loading.
I tried other commands to get the packages or remove the package but all have the same behavior.
What could be a valid reason for that?
Get-AppXProvisionedPackage -Online | Select PackageName
Remove-AppxProvisionedPackage
-PackageName "PackageName" -Online -AllUsers
EDIT#1:I am getting the following error after waiting for long time and pressing PgDn or End buttons on keyboard.
Remove-AppxProvisionedPackage : DismInitialize failed. Error code = 0x80004005
At line:1 char:1
+ Remove-AppxProvisionedPackage -PackageName PACKAGE_NAME ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Remove-AppxProvisionedPackage], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.RemoveAppxProvisionedPackageCommand

Why doesn't "Set-Item" work on Windows 7 PowerShell?

I am trying to install Windows 10 IoT on my Raspberry Pi 2. The PowerShell documentation tells me to put in this:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc>
However, when I put it into my Windows 7 PowerShell, this comes out:
At line:1 char:54
+ Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc>
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
How do I fix this?
You need to use quotes rather than < > around the name of the device (minwinpc)
Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'minwinpc'

Copying directory fails sometimes with "access denied"

I am executing a PowerShell script and this line:
Copy-Item -Path "$A_DIRECTORY" -Destination "$ANOTHER_DIRECTORY" -Recurse -Force
intermittently fails with the following error:
Copy-Item : Access is denied
At C:\mydir\build.ps1:224 char:5
+ Copy-Item -Path "$A_DIRECTORY" -Destination "$ANOTHER_DIRECTORY" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.CopyItemCommand
Now, the error message is clear, but it does not make sense because the target directory does not exist. I have write permissions and also tried to run as administrator with same result.
Why would this statement fail sometimes but not always? Perhaps it is also worth noting that $ANOTHER_DIRECTORY is deleted in the command preceding this one. The delete operation never fails.

Resources