Add-PsSnapin WebAdministration in Windows7 - powershell

I want to use PowerShell to administer my IIS7 on Windows7 64 bits.
I try install IIS7 Powershell snap-in http://www.iis.net/download/PowerShell
I "Run as administrator", then typing the command listed below: msiexec /I iis7psprov_x64.msi but I get this error message: "The PowerShell snap-in is part of Windows Operating System. Please install via Programs and Features or Server Manager"
I think this particular feature is not necessary to load the WebAdministration module but I active all options in "Programs and features |
turn Windows features on or off | IIS | Web Management Tools | IIS Management Scripts and Tools
I do those checks:
1.) Power-Shell is installed
PS C:\Program Files\IIS> $Host.Version
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
PS C:\Program Files\IIS> $PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.5448
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
PS C:\Program Files\IIS> get-host
Name : ConsoleHost
Version : 2.0
InstanceId : 445ad8f5-87fc-48f7-b010-f7faf948b86c
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : es-ES
CurrentUICulture : es-ES
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
2.) Set-ExecutionPolicy -ExecutionPolicy {Your Execution Policy}
PS C:\Program Files\IIS> get-ExecutionPolicy
Unrestricted
3.)Import-Module WebAdministration
PS C:\Program Files\IIS> Import-Module WebAdministration
PS C:\Program Files\IIS>
4.) C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration path exists
5.) Modules and Snap-in
PS C:\Program Files\IIS> get-module -listavailable
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest AppLocker {}
Manifest BitsTransfer {}
Manifest PSDiagnostics {}
Manifest TroubleshootingPack {}
Manifest WebAdministration {}
PS C:\Program Files\IIS> Get-PSSnapin -Registered
Name : SqlServerCmdletSnapin100
PSVersion : 2.0
Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.
Name : SqlServerProviderSnapin100
PSVersion : 2.0
Description : SQL Server Provider
Name : TfsBPAPowerShellSnapIn
PSVersion : 2.0
Description : This is a PowerShell snap-in that includes Team Foundation Server cmdlets.
PS C:\Program Files\IIS> get-pssnapin
Name : Microsoft.PowerShell.Diagnostics
PSVersion : 2.0
Description : Este complemento de Windows PowerShell contiene cmdlets de Eventos de Windows y de contador de rendimient
o.
Name : Microsoft.WSMan.Management
PSVersion : 2.0
Description : Este complemento de Windows PowerShell contiene cmdlets (como Get-WSManInstance y Set-WSManInstance) que
usa el host de Windows PowerShell para administrar operaciones WSMan.
Name : Microsoft.PowerShell.Core
PSVersion : 2.0
Description : Este complemento de Windows PowerShell contiene cmdlets usados para administrar los componentes de Window
s PowerShell.
Name : Microsoft.PowerShell.Utility
PSVersion : 2.0
Description : Este complemento de Windows PowerShell contiene cmdlets de utilidad que sirven para manipular datos.
Name : Microsoft.PowerShell.Host
PSVersion : 2.0
Description : Este complemento de Windows PowerShell contiene cmdlets (como Start-Transcript y Stop-Transcript) proporc
ionados para su uso con el host de la consola de Windows PowerShell.
Name : Microsoft.PowerShell.Management
PSVersion : 2.0
Description : El complemento Windows PowerShell contiene cmdlets de administración para administrar los componentes de
Windows.
Name : Microsoft.PowerShell.Security
PSVersion : 2.0
Description : Este complemento de Windows PowerShell contiene varios cmdlets para la administración de la seguridad de
Windows PowerShell.
PS C:\Program Files\IIS> [System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" )
GAC Version Location
--- ------- --------
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Administration\7.0.0.0__31bf3856ad364e35\Microsoft....
PS C:\Program Files\IIS> (New-Object Microsoft.Web.Administration.ServerManager)
ApplicationDefaults : Microsoft.Web.Administration.ApplicationDefaults
ApplicationPoolDefaults : Microsoft.Web.Administration.ApplicationPoolDefaults
ApplicationPools : {DefaultAppPool}
SiteDefaults : Microsoft.Web.Administration.SiteDefaults
Sites : {Default Web Site}
VirtualDirectoryDefaults : Microsoft.Web.Administration.VirtualDirectoryDefaults
WorkerProcesses : {}
PS C:\Program Files\IIS> (New-Object Microsoft.Web.Administration.ServerManager).Sites
ApplicationDefaults : Microsoft.Web.Administration.ApplicationDefaults
Applications : {Default Web Site/}
Bindings : {[http] *:80:}
Id : 1
Limits : Microsoft.Web.Administration.SiteLimits
LogFile : Microsoft.Web.Administration.SiteLogFile
Name : Default Web Site
ServerAutoStart : True
State : Started
TraceFailedRequestsLogging : Microsoft.Web.Administration.SiteTraceFailedRequestsLogging
VirtualDirectoryDefaults : Microsoft.Web.Administration.VirtualDirectoryDefaults
Attributes : {name, id, serverAutoStart, state}
ChildElements : {bindings, limits, logFile, traceFailedRequestsLogging...}
ElementTagName : site
IsLocallyStored : True
Methods : {Start, Stop}
RawAttributes : {[name, Default Web Site], [id, 1], [serverAutoStart, True], [state, 1]}
Schema : Microsoft.Web.Administration.ConfigurationElementSchema
6.) I try in ps1 file
$succeeded = import-module WebAdministration
Write-Host $succeeded
if (($succeeded -ne $null) -and ($succeeded.GetType() -eq [System.Exception]))
{
#Could not import, trying to snapin
add-pssnapin WebAdministration
}
$succeeded is null, and "add-pssnapin WebAdministration" produces error message: Add-PSSnapin : The Windows PowerShell snap-in 'WebAdministration' is not installed on this machine.
PS C:\Program Files\IIS> Add-PSSnapin WebAdministration
Add-PSSnapin : El complemento WebAdministration de Windows PowerShell no está instalado en este equipo
En línea: 1 Carácter: 13
+ Add-PSSnapin <<<< WebAdministration
+ CategoryInfo : InvalidArgument: (WebAdministration:String) [Add-PSSnapin], PSArgum
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
any suggestions about it ? Why fails Add-PSSnapin WebAdministration ?
UPDATE:
I'm confused when exactly do I use Add-PSSnapin and when do I use Import-Module
http://social.technet.microsoft.com/Forums/en/ITCG/thread/3e1ca6e1-d197-4c04-a145-1e922814a618
surely, WebAdministration is only Module, and has'nt PSSnapin. May be...
References:
PowerShell IIS Snapin
Cannot install Powershell Snap-in
http://www.iis.net/download/PowerShell
http://learn.iis.net/page.aspx/429/installing-the-iis-powershell-snap-in/
http://learningpcs.blogspot.com.es/2010/08/powershell-iis-7-webadministration.html
Versión de PowerShell instalada
Determine installed PowerShell version

Here is the function I have in my profile.ps1 for loading the WebAdmin module. It covers IIS 7 and 7.5
# Web administration is loaded as a module on Windows 2008 R2 but as a set of snapins
# for Windows 2008 (not R2)
function Util-Load-Web-Administration
{
$ModuleName = "WebAdministration"
$ModuleLoaded = $false
$LoadAsSnapin = $false
if ($PSVersionTable.PSVersion.Major -ge 2)
{
if ((Get-Module -ListAvailable | ForEach-Object {$_.Name}) -contains $ModuleName)
{
Import-Module $ModuleName
if ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName)
{ $ModuleLoaded = $true } else { $LoadAsSnapin = $true }
}
elseif ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName)
{ $ModuleLoaded = $true } else { $LoadAsSnapin = $true }
}
else
{ $LoadAsSnapin = $true }
if ($LoadAsSnapin)
{
try
{
if ((Get-PSSnapin -Registered | ForEach-Object {$_.Name}) -contains $ModuleName)
{
if ((Get-PSSnapin -Name $ModuleName -ErrorAction SilentlyContinue) -eq $null)
{ Add-PSSnapin $ModuleName }
if ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName)
{ $ModuleLoaded = $true }
}
elseif ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName)
{ $ModuleLoaded = $true }
}
catch
{
Write-Error "`t`t$($MyInvocation.InvocationName): $_"
Exit
}
}
}

Related

Enable tls1.2 on windows 7 with powershell 2.0

Cannot enable TLS1.2 on Windows 7SP1 with powershell 2.0 :
PS C:\Windows\system32> $PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.8806
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
I guess P.Sv2.0 is using .NET v2.0 :
PS C:\Windows\system32> $PSVersionTable.CLRVersion
Major Minor Build Revision
----- ----- ----- --------
2 0 50727 8806
PS C:\Windows\system32> [System.Environment]::Version
Major Minor Build Revision
----- ----- ----- --------
2 0 50727 8806
Moreover, the following .NET versions are installed on this system :
PS C:\Windows\system32> Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version, Release -ErrorAction 0 | where { $_.PSChildName -match '^(?!S)\p{L}'} | select Version, Release, PSChildName
Version Release PSChildName
------- ------- -----------
2.0.50727.5420 v2.0.50727
3.0.30729.5420 v3.0
3.0.4506.5420 Windows Communication Foundation
3.0.6920.5011 Windows Presentation Foundation
3.5.30729.5420 v3.5
4.8.03761 528049 Client
4.8.03761 528049 Full
4.0.0.0 Client
However, I cannot set TLSv1.2 with that configuration :
PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Exception lors de la définition de « SecurityProtocol » : « Impossible de convertir la valeur Null en type « System.Net.SecurityProtocolType » en raison de valeurs d'énumération non valides. Spécifiez l'une des valeurs d'énumération suivantes et réessayez. Les valeurs d'énumération possibles sont « Ssl3, Tls ». »
Au niveau de ligne : 1 Caractère : 28
+ [Net.ServicePointManager]:: <<<< SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
PS C:\Windows\system32> [enum]::GetNames([Net.SecurityProtocolType])
Ssl3
Tls
PS C:\Windows\system32>
EDIT 0 : #mclayton Setting up [Net.ServicePointManager]::SecurityProtocol to the integer value of 3072 does not work either :
PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = 3072
Exception lors de la définition de « SecurityProtocol » : « Impossible de convertir la valeur « 3072 » en type « System.Net.SecurityProtocolType » en raison de valeurs d'énumérati
on non valides. Spécifiez l'une des valeurs d'énumération suivantes et réessayez. Les valeurs d'énumération possibles sont « Ssl3, Tls ». »
Au niveau de ligne : 1 Caractère : 28
+ [Net.ServicePointManager]:: <<<< SecurityProtocol = 3072
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Can you help me ?
To expand on #Abraham Zinala's comment, the Tls12 enumeration value wasn't added to the System.Net.SecurityProtocolType enum until Dot Net Framework version 4.5 (see https://learn.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netframework-4.5).
Your PowerShell 2.0 install is using a lower version than this, so it can't resolve the value of [Net.SecurityProtocolType]::Tls12.
What you can do instead is use the integer value of the enum:
# assign the magic number to a variable for clarity
$tls12 = 3072;
[Net.ServicePointManager]::SecurityProtocol = $tls12;

NoServiceFoundForGivenName when stop another server's service with invoke-command

I have 2 windows server, Server1 (now 2019) and ServerUpdate (2012 R2)
On each server I have an admin user named: AdminUpdate with the same password.
Im currently switching my Server1 windows server 2012 R2 for a windows server 2019. The following powershell code was working #1 before the switch.
I try to run this powershell on ServerUpdate to stop aservice on Server1
# Obtient une instance du mot passe sécurisé
$passwordCred = ConvertTo-SecureString *SomePassword* -AsPlainText -Force
# Obtient les crédentials
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList AdminUpdate, $passwordCred
# Effectue le Stop sur le service
invoke-command -computerName *Server1Ip* -scriptBlock {
# Effectue le stop en local
Stop-Service -Name $args[0] -Force
} -credential $cred -ArgumentList *someServiceName*
For some reason I always got this error:
'*someServiceName*'.
+ CategoryInfo : ObjectNotFound: (*someServiceName*:String) [Stop-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
Commands.StopServiceCommand
+ PSComputerName : *Server1Ip*
But if i try directly this, its return the service
Get-Service -ComputerName *Server1Ip* -Name *someServiceName*
I have check this https://blog.netspi.com/powershell-remoting-cheatsheet/
I have the PSRemoting Enable
I put the sevice WinRM auto
I put my Server1 ip in the Trustedhosts on the ServerUpdate and same for the Server1, I put the ServerUpdate ip in the Trustedhosts
Did someone know why I got this error?

PowerShell and TFS | The term 'tfpt' is not recognized as the name of a cmdlet

Running locally on my client (not TFS server) Windows 10 pro workstation and getting the error. What am I missing?
> tfpt : The term 'tfpt' 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 C:\DeploymentManagement\Tests\GetBranchInfo.ps1:18
> char:21
> + $WorkItemResults = tfpt query /format:tsv /collection:$TfsServer /wi ...
> + ~~~~
> + CategoryInfo : ObjectNotFound: (tfpt:String) [], CommandNotFoundException
> + FullyQualifiedErrorId : CommandNotFoundException The variable '$WorkItemResults' cannot be retrieved because it has not been set. At
> C:\DeploymentManagement\Tests\GetBranchInfo.ps1:19 char:20
> + $WorkItemResults = $WorkItemResults -replace "(.*)Query results:.*", ...
> + ~~~~~~~~~~~~~~~~
> + CategoryInfo : InvalidOperation: (WorkItemResults:String) [], RuntimeException
> + FullyQualifiedErrorId : VariableIsUndefined The variable '$WorkItemResults' cannot be retrieved because it has not been set. At
> C:\DeploymentManagement\Tests\GetBranchInfo.ps1:21 char:20
> + $WorkItemResults = $WorkItemResults.Split("`t")
> + ~~~~~~~~~~~~~~~~
> + CategoryInfo : InvalidOperation: (WorkItemResults:String) [], RuntimeException
> + FullyQualifiedErrorId : VariableIsUndefined The variable '$WorkItemResults' cannot be retrieved because it has not been set. At
> C:\DeploymentManagement\Tests\GetBranchInfo.ps1:24 char:17
> + foreach($row in $WorkItemResults)
> + ~~~~~~~~~~~~~~~~
> + CategoryInfo : InvalidOperation: (WorkItemResults:String) [], RuntimeException
> + FullyQualifiedErrorId : VariableIsUndefined
Code sample below
# Enforce coding rules
Set-StrictMode -version 2.0
# Loads Windows PowerShell snap-in if not already loaded
if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue
}
$PbiParm = 89306
# Get Iteration Path and PBI Title
$query = "SELECT [System.IterationPath], [System.Title] " +
"FROM WorkItems WHERE [System.Id] = " + $PbiParm
$TfsServer = "http://***tfs01:8080/tfs/Project"
$WorkItemResults = tfpt query /format:tsv /collection:$TfsServer /wiql:$query
$WorkItemResults = $WorkItemResults -replace "(.*)Query results:.*", ""
$WorkItemResults = $WorkItemResults.Split("`t")
$Index = 0
foreach($row in $WorkItemResults)
{
$Index++
Write-Host $Index
if ($Index -eq 1 -or $Index -eq 2)
{
continue
}
if ($Index -eq 3)
{
$SprintName = $row
}
if ($Index -eq 4)
{
$PbiTitle = $row
}
if ($Index -eq 5)
{
break
}
}
Tools: PowerShell ISE, TFS Server 2012, Windows PowerShell 2.0 Engine, and also installed:
C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools
C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools
> Get-Host | Select-Object Version >> Version
> -------
> 5.1.17763.1007
Tried to run the command :
powershell -Command get-pssnapin -Registered
RESULT:
Name : SqlServerCmdletSnapin100
PSVersion : 2.0
Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.
Name : SqlServerProviderSnapin100
PSVersion : 2.0
Description : SQL Server Provider
Name : TfsBPAPowerShellSnapIn
PSVersion : 2.0
Description : This is a PowerShell snap-in that includes Team Foundation Server cmdlets.
Name : WDeploySnapin3.0
PSVersion : 2.0
Description : This is a PowerShell snap-in that contains cmdlets for managing Microsoft Web Deployment infrastructure.
SOLVED!
Apparently TFPT Query engine 2010 uses some sort of old exe file that could only be found in
https://marketplace.visualstudio.com/items?itemName=MartinWoodward.TeamFoundationServerPowerToolsDecember2011
Step 1:
run in ISE the following:
notepad $PROFILE
This will open your PowerShell profile script. If the file doesn’t exist, it will prompt you to create it.
Step 2: Add following lines (amke sure files do exist first if you using different version of VS!)
Set-Alias tfpt "C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\tfpt.exe"

PowerShell cmdlet Test-NetConnection not available

I noticed that the cmdlet Test-NetConnection was not installed on Server 2012. Since Server 2012 comes with PowerShell version 3 so I thought it might help to update to the latest version 5.1.
I did the update but the cmdlet Test-NetConnection is still not available.
Only Test-Connection is present, but I need Test-NetConnection to test ports.
How can I get Test-NetConnection now?
PS C:\Windows\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14409.1005
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1005
CLRVersion 4.0.30319.34209
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\Windows\system32> Get-Command Test-NetConnection
Get-Command : The term 'Test-NetConnection' 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
+ Get-Command Test-NetConnection
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Test-NetConnection:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
The availability of many cmdlets is tied to the Windows version, not the PowerShell version. If you can't upgrade your Windows version you can't have Test-NetConnection.
You could use a commandline port scanner like nmap or scanline for port tests, or you could connect to the port(s) yourself:
function Test-Port($server, $port) {
$client = New-Object Net.Sockets.TcpClient
try {
$client.Connect($server, $port)
$true
} catch {
$false
} finally {
$client.Dispose()
}
}
$ipaddress = "serverName"
$port = "portNum"
$connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
if ($connection.Connected) {
Write-Host "Success"
} else {
Write-Host "Failed"
}

Invoke-VMScript Object reference not set to an instance of an object.from VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()

Invoke-VMScript
Object reference not set to an instance of an object.
Which ultimately has come from :
VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()
On my machine, Invoke-VMScript fails when pointing at a VMGuest whose operating system is a flavor of Linux.
* Another developer is able to run this script without problems.
* He and I have matched PowerCLI and Vix versions.
* It is not an authentication problem
** I can go to his machine, use my windows credentials and the script runs
** He can come to my machine, use his windows credentials and the script throws
C:\run_a_bash_script.ps1 :
$my_fullname_vmIpChangeLin_ps1 = ( $MyInvocation.MyCommand.Definition )
$my_dir_vmIpChangeLin_ps1 = ( Split-Path $my_fullname_vmIpChangeLin_ps1 )
import-module "$( $my_dir_vmIpChangeLin_ps1 )\libs\ooooops\ooooops.psm1" -force
Set-StrictMode -Version:Latest
$GLOBAL:ErrorActionPreference = "Stop"
Add-PSSnapin VMware.VimAutomation.Core
. "$( $my_dir_vmIpChangeLin_ps1 )\libs\Initialize-PowerCLIEnvironment.ps1"
[string]$repoServer = <# VCenter FQDN #>
[string]$repoUser = <# AD username #>
[string]$repoPassword = <# password #>
[string]$vmName = <# vm logical name #>
[string]$vmUser = <# username on linux machine #>
[string]$vmPassword = <# password #>
# set to match the working powercli configuration
$null = ( Set-PowerCLIConfiguration -DefaultVIServerMode:Multiple -ProxyPolicy:UseSystemProxy -DisplayDeprecationWarnings:$true -InvalidCertificateAction:Ignore -Confirm:$false )
Connect-VIServer -Server $repoServer -User $repoUser -Password $repoPassword -WarningAction:SilentlyContinue
$script = "ls"
try
{
Invoke-VMScript -VM $vmName -ScriptText $script -GuestUser $vmUser -GuestPassword $vmPassword -Confirm:$false | Select -ExpandProperty ScriptOutput
}
catch
{
$desc = (ooooops_describe_error -obj:$_)
write-host $desc
}
Running the script :
PS c:\> C:\run_a_bash_script.ps1
Script Results :
Name Port User
---- ---- ----
<# VCenter FQDN #> 443 <# AD username #>
========ERROR SUMMARY=========================================================================================
1/14/2014 4:30:22 PM Invoke-VMScript Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
NotSpecified: (:) [Invoke-VMScript], ViError
at <ScriptBlock>, C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1: line 20
VALUE_IS_NULL
at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()
at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.TryValidateVixVersion()
at VMware.VimAutomation.ViCore.Impl.V1.Service.VmGuestServiceImpl.<>c__DisplayClassc.<RunScriptInGuest>b__b(ClientSideTask , Object )
at VMware.VimAutomation.Sdk.Util10.Task.ClientSideTaskImpl.ThreadProc(Object obj)
At C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1:20 char:5
+ Invoke-VMScript -VM $vmName -ScriptText $script -GuestUser $vmUser -GuestPas ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==============================================================================================================
BEGIN---> describe_error_briefly
BEGIN---> exception
exception =[NULL]
END---> exception
BEGIN---> run_time_exception
is a runtime exception? =[NO]
END---> run_time_exception
BEGIN---> error_record
CategoryInfo =[NotSpecified: (:) [Invoke-VMScript], ViError]
ErrorDetails =[VALUE_IS_NULL]
FullyQualifiedErrorId =[Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript]
ScriptStackTrace =[at <ScriptBlock>, C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1: line 20]
TargetObject =[VALUE_IS_NULL]
BEGIN---> exception
Data =[System.Collections.ListDictionaryInternal]
Message =[1/14/2014 4:30:22 PM Invoke-VMScript Object reference not set to an instance of an object. ]
Source =[VALUE_IS_NULL]
StackTrace =[VALUE_IS_NULL]
TargetSite =[VALUE_IS_NULL]
BEGIN---> exception
Data =[System.Collections.ListDictionaryInternal]
Message =[Object reference not set to an instance of an object.]
Source =[VMware.VimAutomation.ViCore.Impl]
StackTrace =[ at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.GetVixVersion()
| at VMware.VimAutomation.ViCore.Impl.V1.VixHelper.TryValidateVixVersion()
| at VMware.VimAutomation.ViCore.Impl.V1.Service.VmGuestServiceImpl.<>c__DisplayClassc.<RunScriptInGuest>b__b(ClientSideTask , Object )
| at VMware.VimAutomation.Sdk.Util10.Task.ClientSideTaskImpl.ThreadProc(Object obj)]
TargetSite =[System.String GetVixVersion()]
BEGIN---> exception
exception =[NULL]
END---> exception
END---> exception
END---> exception
BEGIN---> invocation_info
PositionMessage =[At C:\projects\github\nodeVM\scripts\powershell\vmIpChangeLin.ps1:20 char:5
|+ Invoke-VMScript -VM $vmName -ScriptText $script -GuestUser $vmUser -GuestPas ...
|+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]
END---> invocation_info
END---> error_record
END---> describe_error_briefly
The method does not seem to exist
both of these return $null
write-host ( [VMware.VimAutomation.ViCore.Impl.V1.VixHelper] | Get-Member -MemberType:All | Where-Object { $_.Name -like "%ersion%" } | Format-Table | Out-String )
and
write-host ( [VMware.VimAutomation.ViCore.Impl.V1.VixHelper] | Get-Member -MemberType:All -Static | Where-Object { $_.Name -like "%ersion%" } | Format-Table | Out-String )
Windows Os, ControlPanel / Programs / Programs and Features
VMWare VIX 1.12.1.33347
VMWare vSphere PowerCLI 5.5.0.5836
PowerCLI Versions / Configuration
Function get_debug_info()
{
write-host "-----------Get-PowerCLIConfiguration--------------------------------------------------"
write-host ( Get-PowerCLIConfiguration | Format-List | Out-String )
write-host "-----------Get-PowerCLIVersion--------------------------------------------------"
write-host ( Get-PowerCLIVersion | Format-List | Out-String )
return $null
}
For the one that works
-----------Get-PowerCLIConfiguration--------------------------------------------------
DefaultVIServerMode : Multiple
ProxyPolicy : UseSystemProxy
DisplayDeprecationWarnings : True
InvalidCertificateAction : Ignore
WebOperationTimeoutSeconds : 300
VMConsoleWindowBrowser :
Scope : Session
DefaultVIServerMode : Multiple
ProxyPolicy :
DisplayDeprecationWarnings :
InvalidCertificateAction :
WebOperationTimeoutSeconds :
VMConsoleWindowBrowser :
Scope : User
DefaultVIServerMode : Single
ProxyPolicy :
DisplayDeprecationWarnings : True
InvalidCertificateAction : Ignore
WebOperationTimeoutSeconds :
VMConsoleWindowBrowser :
Scope : AllUsers
-----------Get-PowerCLIVersion--------------------------------------------------
Major : 5
Minor : 5
Build : 1295336
Revision : 0
Copyright : Copyright © VMware, Inc. 1998-2013
Company : VMware, Inc.
UserFriendlyVersion : VMware vSphere PowerCLI 5.5 Release 1 build 1295336
SnapinVersions : {VMWare AutoDeploy PowerCLI Component 5.5 build 1262826, VMWare ImageBuilder PowerCLI Component 5.5 build 1262826, VMware License PowerCLI Component 5.5 build 1265954, VMware VDS PowerCLI Component 5.5 build 1295334...}
For the one that does not work
-----------Get-PowerCLIConfiguration--------------------------------------------------
DefaultVIServerMode : Single
ProxyPolicy : UseSystemProxy
DisplayDeprecationWarnings : True
InvalidCertificateAction : Ignore
WebOperationTimeoutSeconds : 300
VMConsoleWindowBrowser :
Scope : Session
DefaultVIServerMode : Single
ProxyPolicy :
DisplayDeprecationWarnings :
InvalidCertificateAction :
WebOperationTimeoutSeconds :
VMConsoleWindowBrowser :
Scope : User
DefaultVIServerMode : Multiple
ProxyPolicy : UseSystemProxy
DisplayDeprecationWarnings : True
InvalidCertificateAction : Ignore
WebOperationTimeoutSeconds :
VMConsoleWindowBrowser :
Scope : AllUsers
-----------Get-PowerCLIVersion--------------------------------------------------
Major : 5
Minor : 5
Build : 1295336
Revision : 0
Copyright : Copyright © VMware, Inc. 1998-2013
Company : VMware, Inc.
UserFriendlyVersion : VMware vSphere PowerCLI 5.5 Release 1 build 1295336
SnapinVersions : {VMWare AutoDeploy PowerCLI Component 5.5 build 1262826, VMWare ImageBuilder PowerCLI Component 5.5 build 1262826, VMware License PowerCLI Component 5.5 build 1265954, VMware VDS PowerCLI Component 5.5 build 1295334...}
I had faced the same problem. My Invoke-VMScript was not working. After digging deep into it I found my vCenter server(in my case the target server) was having ipv6 configuration. I removed the ipv6 configuration and changed it to ipv4 configuration.
My issue got resolved.
As described here:
* http://www.virten.net/2013/06/run-scripts-in-linux-guests-by-using-vmware-tools/
* http://www.lucd.info/2012/01/01/will-invoke-vmscript-work/
* https://communities.vmware.com/message/2314207
The problem is that the VIX libraries are 32 bit and I was running the script using 64 bit Powershell.
On a 64 bit OS :
* Powershell 64 bit is the default
* the path to the 32 bit Powershell is : %systemroot%\syswow64\windowspowershell\v1.0\
A simple powershell statement to test if the powershell process is 32 or 64 bit:
[Environment]::Is64BitProcess