PowerShell コマンドが認識されなくなりました

PowerShell コマンドが認識されなくなりました

Chocolately を使用して Win7 x64 コンピューターにパッケージをインストールしました。インストールの一環として、PowerShell を 5.0 にアップグレードする必要がありました。これが発生し、基本的な PowerShell コマンドが機能しなくなりました。Web で検索してみましたが、役に立つものは見つかりませんでした。どうしたらよいのか本当にわかりません。

次に例を示します。

PS>Get-Location
Get-Location : The term 'Get-Location' 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-Location
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Location:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS>

たとえば、コマンドのエイリアスが解決されていることがわかります。

PS>dir
dir : The term 'Get-ChildItem' 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
+ dir
+ ~~~
    + CategoryInfo          : ObjectNotFound: (Get-ChildItem:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS>

$profile に別のエイリアスが設定されており、認識されていることがわかります。xx と入力すると、PowerShell インスタンスが閉じます。

function global:xx
{   
    exit
}

$env:psmodulepath は正しいようです:

PS>$env:psmodulepath
C:\Users\myuserid\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\;C:\w
indows\system32\WindowsPowerShell\v1.0\Modules";C:\Program Files\WindowsPowerShell\Modules
PS>cmd
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\windows\system32>dir c:\windows\system32\WindowsPowerShell\v1.0\Modules
 Volume in drive C is OS
 Volume Serial Number is 605E-A0FF

 Directory of c:\windows\system32\WindowsPowerShell\v1.0\Modules

06/22/2016  11:41 PM    <DIR>          .
06/22/2016  11:41 PM    <DIR>          ..
05/20/2016  02:24 PM    <DIR>          ApplicationServer
06/22/2016  11:41 PM    <DIR>          CimCmdlets
06/22/2016  11:41 PM    <DIR>          ISE
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Archive
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Diagnostics
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Host
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Management
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.ODataUtils
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Security
06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Utility
06/22/2016  11:41 PM    <DIR>          Microsoft.WSMan.Management
06/22/2016  11:41 PM    <DIR>          NetworkSwitchManager
06/22/2016  11:41 PM    <DIR>          PSDesiredStateConfiguration
06/22/2016  11:41 PM    <DIR>          PSDiagnostics
06/22/2016  11:41 PM    <DIR>          PSScheduledJob
06/22/2016  11:41 PM    <DIR>          PSWorkflow
06/22/2016  11:41 PM    <DIR>          PSWorkflowUtility
11/21/2010  02:24 AM    <DIR>          TroubleshootingPack
10/31/2014  04:26 PM    <DIR>          WebAdministration
               0 File(s)              0 bytes
              21 Dir(s)   2,301,882,368 bytes free

C:\windows\system32>

答え1

PowerShellコマンドが機能しなくなった

$env:psmodulepath は正しいようです:

$env:psmodulepath
C:\Users\myuserid\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\;C:\windows\system32\WindowsPowerShell\v1.0\Modules";C:\Program Files\WindowsPowerShell\Modules

"の真ん中に (二重引用符)があります$env:psmodulepathが、私のインストールでは存在しません。

PS F:\test> $env:psmodulepath
C:\Users\DavidPostill\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules

明示的に設定することで二重引用符を削除できます$env:psmodulepath

関連情報