I migrated from PowerCLI 6.3 to latest (10.11) in Windows 2012.
I create test.ps script but when I run it I got:
C:\Windows\System32\WindowsPowerShell\v1.0\powersell.exe -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\" $true". : The term 'C:\Program Files (x86)\VMware\Infrastructure\vSpherePowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' 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:3
+ . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scri ...
As if There was link to Initialize-PowerCLIEnvironmet.ps1 file but I'm not able to understand where is it?
This happens only if I click on script because if I open manually powershell by Windows link and I run command there is no problem, but I lost automatically mechanism!
Suggestions please?
If you are using PowerCLI 10.1.0, you don't need that Init script anymore (module auto loading does that for you).
But can you clarify a bit how you start the script?
Is that from a shortcut on your desktop?
If yes, you will have to update the shortcut?
Or is that from a .ps1 file in the Windows Explorer?
In that case you probably defined an association for the filetype .ps1.
In that association you also have to remove the Init file.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
.ps1 is file which I created by notepad in the Windows Explorer.
I verified that .ps1 is just associated to PowerShell
Can you let us know what this returns?
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR | Out-Null
Get-Item "HKCR:\$($assoc.split('=')[0])\OpenWithProgids"
Get-Item HKCR:\$($assoc.split('=')[1])\Shell\Open\Command
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried 2 test.
1st test.
I opened PowerShell console, I run script .ps1 which you described.
Here is output:
Get-Item : Cannot find path 'HKCR:\.ps1\OpenWithProgids' because it does not exist.
At C:\Users\administrator.AUSL6\Desktop\test cruscotto auto di battaglia\prova.ps1:3 char:1
+ Get-Item "HKCR:\$($assoc.split('=')[0])\OpenWithProgids"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HKCR:\.ps1\OpenWithProgids:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
Hive: HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open
Name Property
---- --------
Command (default) : "C:\Windows\System32\notepad.exe" "%1"
2nd test.
I Open by, Windows Explorer, new windows and I click on script ps1 which you described.
I got :
. : The term 'C:\Program Files (x86)\VMware\Infrastructure\vSpherePowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' 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:3
+ . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program File...Environment.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This is very strange, the output clearly shows that when you double-click a .ps1 file, it would open in notepad.
Which is the default when PowerShell is just installed.
The execution, with the obsolete Init script, must be coming from somewhere else.
Btw, did you already try running your original script from within the PowerShell ISE?
That shouldn't call that Init script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried now.
When I run script inside PowerShell ISE, a new window is opened where I have the same output:
C:\Users\administrator.... >C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\" $true"
. : The term 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' 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:3
+ . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program File...Environment.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This message appears for every script I run.
I meant from an editor window with the F5 key, not from the console command line in the ISE.
Does this for example also happen when you place a single cmdlet (for example Get-Process) in the Editor, and then press F5?
Do you have anything in this variable $CONSOLEFILENAME?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A view on the full content of the script, mask out confidential information, might be useful.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@
I meant from an editor window with the F5 key, not from the console command line in the ISE.
Yes, this occurs in editor windows too, pressing F5 key. Everything I write inside file, It's has the same result.
If I open PowerShell and I type script name (test.ps1) which has a simple connectin to server (connect-viserver -server ...) got the same error.
Does this for example also happen when you place a single cmdlet (for example Get-Process) in the Editor,
Yes, I tried. I got the same result.
I have no set variable as $CONSOLEFILENAME
Would you mind attaching a screenshot of such a run in the ISE?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference