2017-09-08 6 views
0

Get-WmiObjectをソフトウェアに追加する際にエラーが発生しました。私は、コードを続行する前にアプリケーションが現在インストールされているかどうか確認したいのですが、私はそれを実行したとき、私はエラーを取得:ここコードでGet-WmiObjectが認識されない

Get-WmiObject : The term 'Get-WmiObjectÂ' 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:\code\getwmiobj.ps1:1 char:1 + Get-WmiObject -Class "win32_Product" -ComputerName "$computer" | ... + ~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-WmiObjectÂ:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

は私のコードです:

$choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Y","&N") 
while ($true) 
{ 
$computer= Read-Host "Computer that needs software installed or uninstalled" 
Get-WmiObject -Class "win32_Product" -ComputerName "$computer" | Out-GridView -Title "list of programs installed" 
$installed = read-host "Is the software already installed (Y or N)?" 
if ($installed -eq "N") 
    { 

    if (!$computer) 
     { 
     Write-Host "You did not give me a computer name. Please re-run with computer name or IP address" 
     Pause 
     Exit 
     } 

    $ping = (Test-Connection -ComputerName $computer -Count 1 -quiet) 
    $build= "c$\build\" 
    $psexec= "\\bconac01\ds-support\gs_IT\office\scripts, Fixes and Tools\Remote install tool\Common install\psExec64.exe" 
    $deployappexe="\\bconac01\ds-support\gs_IT\office\scripts, Fixes and Tools\Remote install tool\Common install\Deploy-Application.exe" 
    $deployappcfg="\\bconac01\ds-support\gs_IT\office\scripts, Fixes and Tools\Remote install tool\Common install\Deploy-Application.exe.config" 
    $swType= Get-ChildItem "\\bconac01\ds-prod\apps\DesktopServices" | Out-GridView -Title "Type of install needed" -PassThru | Select-object 
    $SW= Get-ChildItem "\\bconac01\ds-prod\apps\DesktopServices\$swType\" | Out-GridView -Title "What do you want to install" -PassThru | Select-object 
    $swloc= "\\bconac01\ds-prod\apps\DesktopServices\$swType\$SW\package\" 
    $ps= Get-ChildItem $swloc | Out-GridView -Title "what installer would you like to use?" -PassThru | Select-Object -expandproperty name 
    $uninstall= read-host "Is this an uninstall? (Y or N) (Default is install)" 
    if ($uninstall -eq "Y") {$installchoice= "uninstall"} else {$installchoice= "install" } 



     if ($ping -eq "true") 
      { 

      Copy-item -Path $swloc -Recurse -Destination \\$computer\$build 
      Copy-Item -Path $psexec -Destination \\$computer\$build\package 
      Copy-item -Path $deployappexe -Force -Destination \\$computer\$build\package 
      Copy-item -Path $deployappcfg -Force -Destination \\$computer\$build\package 
      Set-Location \\$computer\$build\package 
      .\psExec64.exe \\$computer "\\$computer\$build\package\Deploy-Application.exe" "$ps" -DeploymentType "$installchoice" -DeployMode "Interactive" 
      Set-Location -Path 'C:\Code' 
      Remove-item -Path \\$computer\$build\package -Recurse -Force 
      Write-Host " $installchoice of $SW on $computer is complete." 
      Pause 
      } 
     else 
      { 
      Write-Host "Unable to ping $computer at this time. Try re-running with the computers IP address" 
      Pause 
      } 
     } 
else 
    { 
    $choice = $Host.UI.PromptForChoice("Repeat the script?","",$choices,0) 
    if ($choice -ne 0) 
     { 
     break 
     } 
    } 

$choice = $Host.UI.PromptForChoice("Repeat the script?","",$choices,0) 
if ($choice -ne 0) 
    { 
    break 
    } 
} 
+4

これは明らかにエンコードの問題です。あなたのスクリプトは 'utf8'でエンコードされていますか? – TheIncorrigible1

+0

私はそれが何を意味するのか分かりません。私はちょうど私の同僚にそれを実行させて、それは彼の窓10のマシンで働いたので、何かが私のマシンで明らかに間違っています... – aroden20

答えて

1

あなたは別の言語を持っていますかパッケージがインストールされている?それは明らかにÂについて不平を言う。つまり、あなたが別の地域でそれを書いた誰かのブログ/コードをコピーして貼り付けた場合、それは特殊文字を持つかもしれません。

修正:手動でコマンドを書き直してください。メモ帳に貼り付けて、何が現れるかを確認します。メモ帳でスクリプトを開くと、何が間違っているかがわかります。

+0

get-wmiobjectを実行して、あなたの修正が機能しました。助けてくれてありがとう!とても有難い! – aroden20

-1

コードを新しい.ps1ファイルにコピーして実行することで、このエラーを修正できました。それ以外の変更はありませんでした。 :P

関連する問題