Hi we have 6 Vspher server and my Vcenter is Linux Based and version is Vsphere 5.5 .
We are trying manage our VMware environment automatically via PowerCLI script .
I got a script on internet but getting error . Thanks to Lucd and Kunaludapi for helping.
Need some help on this.
Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.Vi
Core.Types.V1.Inventory.VIContainer' required by parameter 'Destination'. Speci
fied method is not supported.
At C:\Scheduled tasks\Vmware DRS Script.ps1:103 char:53
+ $objVM | move-vm -destination <<<< (get-vmhost $strDe
st);
+ CategoryInfo : InvalidArgument: (:) [Move-VM], ParameterBinding
Exception
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.MoveVM
google is your friend
http://kc-tek.blogspot.co.nz/2012/06/vmotion-vms-from-one-given-host-to.html
As always when using PowerCLI you have to connect to your vCentre server
Connect-VIserver SeverName
Issue the command to 'get' the VMs from the host you want to move them off and then 'move' them to the target host.
Get-VM -Location "HostName" | Move-VM -Destination (Get-Vmhost "NewHost")
Related
I'm trying to run a windows vm in virtualbox and use it as a runner in git lab, following https://docs.gitlab.com/runner/executors/virtualbox.html#use-native-openssh-and-powershell
I installed native open ssh, git for windows and configured the default shell to be pwsh as they request:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "$PSHOME\pwsh.exe" -PropertyType String -Force
however SSH does not work. When I try to ssh to localhost:
ssh MACHINE_NAME\username#localhost
I get Permission denied, try again
when I do this. If I do
reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
then I can ssh into my machine. THe gitlab can also, but then it complains that bash is not a command on power shell:
00:02
bash : The term 'bash' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:1 char:1
+ bash -l
+ ~~~~
+ CategoryInfo : ObjectNotFound: (bash:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
ERROR: Job failed: prepare environment: Process exited with status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
To fix that, I installed WSL and ubuntu on Windows, but then it gives
ERROR: Job failed: prepare environment: Process exited with status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
this is a known problem in ubuntu which is fixed by removing .bash_logout but I can't do this to the WSL image. Also, installing WSL shouldn't be the way here, it should work without WSL.
I am pretty new to Azure and TFS and related. So please excuse me if I mix up the terms here.
I am testing the capabilities of Microsoft Team Foundation Server with an on-premise installation. I am not the admin of the server itself, I have admin access to one of the projects inside.
I have a git repo with some python code in this project and I am trying to set up CI build pipeline for this. I am also manually configuring an agent to run this build pipeline. For the timebeing, I am configuring the windows machine that I am working on to run as an agent. I was able to set it up to listen for jobs and also it picks up the job when submitted from the TFS server. (I am running the agent from a cmd.exe window)
However, I couldn't get it do even the simplest of command line tasks as part of the build pipeline.
Below is the output of where python:
2019-08-27T14:41:15.1614046Z ##[section]Starting: Find python version
2019-08-27T14:41:15.1623937Z ==============================================================================
2019-08-27T14:41:15.1624042Z Task : Command Line
2019-08-27T14:41:15.1624091Z Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-08-27T14:41:15.1624157Z Version : 2.146.1
2019-08-27T14:41:15.1624203Z Author : Microsoft Corporation
2019-08-27T14:41:15.1624258Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-08-27T14:41:15.1625058Z ==============================================================================
2019-08-27T14:41:15.6151701Z Cannot invoke method. Method invocation is supported only on core types in this language mode.
2019-08-27T14:41:15.6151921Z At line:1 char:1
2019-08-27T14:41:15.6151968Z + . ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPa ...
2019-08-27T14:41:15.6152019Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-27T14:41:15.6152077Z + CategoryInfo : InvalidOperation: (:) [], RuntimeException
2019-08-27T14:41:15.6152123Z + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
2019-08-27T14:41:15.6152156Z
2019-08-27T14:41:17.7569608Z Cannot invoke method. Method invocation is supported only on core types in this language mode.
2019-08-27T14:41:17.7569833Z At line:1 char:740
2019-08-27T14:41:17.7570630Z + ... Continue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create ...
2019-08-27T14:41:17.7571090Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-27T14:41:17.7572452Z + CategoryInfo : InvalidOperation: (:) [], RuntimeException
2019-08-27T14:41:17.7574051Z + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
2019-08-27T14:41:17.7574178Z
2019-08-27T14:41:17.8271008Z ##[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name 'C:\TOOLS\agent\_work\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.146.1\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList #{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\TOOLS\agent\_work\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.146.1\cmdline.ps1'''))"'.
2019-08-27T14:41:17.8301183Z ##[section]Finishing: Find python version
This command runs fine when I execute it from a commandline interactively in my machine.
Why is the PowerShell getting invoked when the pipeline runs? And why such a long command to execute something so simple?
Thanks in advance for any suggestions you can give.
The agent uses PowerShell behind the scenes, it looks like your IT put some security in the computers that blocked running some PowerShell scripts (maybe only it from remote).
Try to run it in your PowerShell:
$ExecutionContext.SessionState.LanguageMode
I guess you will get this output:
ConstrainedLanguage
If yes, try to switch it to FullLanguage:
$ExecutionContext.SessionState.LanguageMode = "FullLanguage"
If it doesn't help maybe it's also blocked, so you need to talk with IT that will change it or try to change the registry like explained here or set the environment variable __PSLockdownPolicy to 0.
I have create Azure SQL Managed Instance and I want to create client VM that will be used to access the instance. I have copied the configuration script from the Azure portal:
When I execute this script via PowerShell, I'm getting the following error:
New-AzureRmResourceGroupDeployment : 5:06:13 PM - Error: Code=InvalidTemplateDeployment; Message=The template deployment 'azuredeploy' is not valid according to the
validation procedure. The tracking id is '8bc76e8d-3070-44a3-bc43-58bbeeac20d8'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details.
At line:179 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 5:06:14 PM - Error: Code=QuotaExceeded; Message=Operation results in exceeding quota limits of Core. Maximum allowed: 100, Current
in use: 100, Additional requested: 2. Please read more about quota increase at http://aka.ms/corequotaincrease.
At line:179 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
If these some explanation why this error happens and hot to see what is the current quota?
The first error shows that you have InvalidTemplateDeployment. You could execute this script with Invoke-Command here to run commands on local and remote computers. Once you copy this script to your power shell command line, you would need to set the password for VM and execute the script. Once you execute the script, you will see that it deployed your VM. You can get more details from this step by step.
For the second error. The quota is for each individual region, not for the entire subscription. You can use the Get-AzureRmVMUsage -Location "South Central US" command to find virtual machine quotas with a specific location. You can get more reference about resolving errors for resource quotas.
Created Azure file share in portal and copied the PowerShell script to connect it as drive Q: (verified not in use). Response:
New-PSDrive : The network resource type is not correct
At line:3 char:1
+ New-PSDrive -Name Q -PSProvider FileSystem -Root "\\xxxx.file.c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Q:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
where "xxxx" is the share name. The PS command was copied directly from the portal and not altered.
As noted in comments above, Comcast blocks port 445. Solution was to have another object in the cloud reference the Azure File and then return the data to the client over HTTP.
Several workaround for port 445 (SMB port) being blocked are listed here:
https://learn.microsoft.com/en-us/azure/storage/files/storage-troubleshoot-windows-file-connection-problems#error-53-error-67-or-error-87-when-you-mount-or-unmount-an-azure-file-share
Some days ago, i was able do create a remote session using short name of the remote server/workstation.
This doesnt work anymore error is :
+ CategoryInfo : InvalidArgument : (computername1:String) [Enter-PSSession], PSRemotingTransportExcepti
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
but when i use the complete domain name it is working :
nsn computername1.domain.com
Dns resolution is correct, what else can i check to troubleshoot this problem ?
I've finaly found it ! :)
I had to modify the default pssession option and set the proxy to 'NoProxyServer' instead of the default value 'none'
so I added this line in my profile :
$PSSessionOption = New-PSSessionOption -ProxyAccessType NoProxyServer
From technet :
None The proxy access type is not specified. This means that proxy
information, such as the access type, authentication mechanism, and
credential, is not passed to the Web Services for Management (WSMan)
protocol service. This field is introduced in Windows PowerShell 2.0.
NoProxyServer No proxy server is used when configuring proxy settings.
This mechanism resolves all the host names locally. This field is
introduced in Windows PowerShell 2.0.
As i cant find the source of the problem here is my workaround :
rename the two aliases nsn and etsn and replace them by these functions in my profile :
rename-item alias:\nsn nsn2 -ea silentlycontinue
rename-item alias:\etsn etsn2 -ea silentlycontinue
function resolve-hostname{
param($computername)
[System.Net.Dns]::GetHostEntry($computername) |select -ExpandProperty hostname
}
function nsn{
param($computername)
$cn=resolve-hostname $computername
new-pssession -cn $cn
}
function etsn{
param($computername)
$cn=resolve-hostname $computername
enter-pssession -cn $cn
}