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
}
Related
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 am trying to programmatically add tags to resources in Azure Government. When I try to set the tags on a resource that has no tags I am using the Set-AzureRmResource command. I have tried both setting the ApiVersion and without (without is supposed to use the latest) When I use the Debug flag it shows the version being set but I still get an error below.
Set-AzureRmResource : Cannot validate argument on parameter 'ResourceId'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:1 char:108
+ ... ONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-AzureRmResource], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implem
entation.SetAzureResourceCmdlet
The snippet I am trying to run is below.
Set-AzureRmResource -Tag #{ ENVIRONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force
Edit: Specify Azure Government
Edit 2: Removed explicit version setting from code
I tried using the new Az commands in Azure Government:
Set-AzResource -Tag #{ ENVIRONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force
..and it worked fine for me. (I got a serialization error using the older AzureRm commands). FYI... not sure when you tried it yesterday, but there was a DNS issue that caused some service outages, which may have resulted in erroneous errors.
I tested your snippet above against an Azure Government resource and its working correctly using AzureRM module version 6.13.1.
You can your version by running this snippet
Get-Module AzureRM -List
For anyone who sees this in the future. The problem is a known bug in the way Azure encodes the '#' symbol in a ResourceId. So do not use '#' in a resource string.
The code change we are making is to use the following:
$resource.ResourceId = $resource.ResourceId.Replace("#", "%23")
Simple fix if you have the # symbol, or change your governance to not name things with '#'.
Thanks for all the other replies. We had to open a ticket to get this information.
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")
Does anybody know how to resolve this issue?
Replicate when you type the following command in PowerShell.
dir iis:\sslbindings
I have comes across this page on Microsoft TechNet which doesn't address the problem.
Edit
When invoking the command I get the error
failed to enumerate SSL bindings
Apparently due to a corrupted registry?
In my case, I've got the error when I had both SslCertStoreName and DefaultSslCtlStoreName in the registry. I deleted DefaultSslCtlStoreName and the error is gone for a while. For some reason, DefaultSslCtlStoreName was created in the registry again, and I've got the error again. So I wrote a simple powershell script that deletes it.
This is the part from my build script.
function CleanupSslBindings()
{
$sslBindingsPath = 'hklm:\SYSTEM\CurrentControlSet\services\HTTP\Parameters\SslBindingInfo\'
$registryItems = Get-ChildItem -Path $sslBindingsPath |
Where-Object -FilterScript { ($_.Property -eq 'DefaultSslCtlStoreName')}
If ($registryItems.Count -gt 0) {
ForEach ($item in $registryItems) {
$item | Remove-ItemProperty -Name DefaultSslCtlStoreName
Write-Host "Deleted DefaultSslCtlStoreName in " $item.Name
}
} Else {
Write-Host "No DefaultSslCtlStoreName found. The SSL Bindings registry is clean."
}
}
In my case, I had built WCF services hosted as windows services. When I did this, I apparently didn't know (and still don't) how to assign things like appid's (noticeable when you netsh http show sslcert), and other items that crop up... including an item related to this error.
Essentially, I read the same page the OP did: https://social.technet.microsoft.com/Forums/windowsserver/en-US/87b1252d-a6a0-4251-bbb6-38e104a8c07a/enumerating-iissslbindings-gives-failure-on-one-machine-works-on-another?forum=winserverpowershell
...and using a regedit, went to the key: HKLM\System\Currentcontrolset\services\http\parameters\sslbindinginfo
I saw all the same entries I see when I do the netsh command above. However, my wcf services are listed first, followed by my IIS sites. None of my wcf services had the SSLCertStoreName key (only the IIS sites had the key). Following the article's explanation that the first entry needs to have that registry key (this is a bug in my opinion), I performed the following PowerShell commands:
Try
{
Get-ChildItem IIS:\SslBindings
}
Catch
{
$1stentry = Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\services\HTTP\Parameters\SslBindingInfo | Select-Object -First 1
$1stentry | New-ItemProperty -Name "SslCertStoreName" -Value "MY"
Get-ChildItem IIS:\SslBindings
}
This code works for me. And that article helped get me here and understand that my root cause of this 234 error code, is an assumed self-inflicted wound by not installing my WCF services correctly. YMMV. Hope this helps.
Apologies for the delay but I resolved the issue with the following script (see below). For some bizarre reason (I don't know why) something was adding two entries in my registry and after removing these the problem went away. I figured this out as I compared my registry to another machine who wasn't having this problem and found the culprit.
Remove-ItemProperty -Path "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters\SslBindingInfo\" -Name "[::1]:26143" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters\SslBindingInfo" -Name "127.0.0.1:26143" -ErrorAction SilentlyContinue
echo "Done."
#Bewc I reckon you are onto something there although I think it affects more than just WCF services. We have a powershell script that builds and deploys a website onto a machine (sounds crazy I know). Who or what creates these entries I have no idea but perhaps some background process in IIS?
I am trying to add an MSMQ binding for my IIS Web Site, correct binding should look like this:
So I am executing following line in PowerShell:
New-WebBinding -Name "My Site" -Protocol net.msmq -HostHeader "localhost"
and it creates the following binding:
prefixing it with *:80:, so my MSMQ messages don't get picked up by WCF service. Maybe I am doing it wrong? How to create a binding with Binding Information set to just "localhost" using this PowerShell comandlet?
Commandlet codumentaiton can be found here.
Looking at the decompiled code of the cmdlet, looks like it adding the IPAddress and Port information in the binding and there is no workaround to it.
Relevant sections from the code:
private string ipAddress = "*";
...
builder.Append(this.ipAddress);
...
builder.Append(":" + this.sitePort.ToString(CultureInfo.InvariantCulture) + ":");
But you can do what the cmdlet actually does ( below code from cmdlet):
new-itemproperty -path "IIS:\sites\test" -name bindings -value #{protocol="net.msmq"; bindingInformation="localhost"}
Give this a try:
New-ItemProperty "IIS:\sites\NameOfYourSite" -name bindings -value #{protocol="net.msmq";bindingInformation="localhost"}
If your are running PowerShell (Core), a.k.a PowerShell >v7.1.x, you will find yourself in trouble because...
WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session;
please note that all input and output of commands from this module will be deserialized objects.
If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.
The IIS provider isn't available via remoting session.
The easiest trick is to redirect string via pipeline to Windows PowerShell.
"Import-Module WebAdministration;New-ItemProperty -Path `"IIS:\Sites\$($configuration.Website.Name)`" -Name Bindings -value #{protocol = `"net.msmq`"; bindingInformation = `"localhost`" }" | PowerShell
In this example, the website name is read from the configuration JSON. You can replace it by a hard-coded site name.