VMを無視している間に、自分の環境内の物理的なワークステーションからVMware Toolsを削除するPowerShellスクリプトを作成しようとしています"#物理的な場合はVMware Toolsの削除を実行し、ログにはのログを書き込んでください"のネストされたif/else文で問題が発生します。 Powershellの経験が豊富な方は、私が間違っている可能性のあることについていくつか指摘できますか?他Powershellのネストされたコマンドレットの名前として認識されない場合
:「他に」は、コマンドレット、関数、スクリプトファイル、または操作可能なプログラムの名前として認識されていない用語
は、私は、次のエラーメッセージが表示されます。名前の綴りを確認するか、パスが含まれている場合は、パスが正しいことを確認してから を再度試してください。
アマチュアの書式設定についてお詫び申し上げますが、私はPowershellをまだ学んでいます。
ありがとうございました。
#Create log path
$path = "D:\log\folder\location\"
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
#Gather required host info
$ComputerSystemInfo = Get-WmiObject -Class Win32_ComputerSystem -
ComputerName $env:COMPUTERNAME -ErrorAction Stop
switch ($ComputerSystemInfo.Model) {
# Check for VMware Machine Type
"VMware Virtual Platform" {
$MachineType = "VM"
}
# Otherwise it is a physical Box
default {
$MachineType = "Physical"
}
}
#Execute VMware Tools removal if physical, then write log
if($MachineType -eq "Physical") {
$regpath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\uninstall"
Get-childItem $regpath | % {$keypath = $_.pschildname
$key = Get-Itemproperty $regpath\$keypath}
if($key.DisplayName -match "VMware Tools")
{$VMwareToolsGUID = $keypath} MsiExec.exe /x $VMwareToolsGUID /qn /norestart
{Write-output "VMware Tools Uninstalled" | Out-File -Encoding ascii -filepath "D:\log\folder\location\VMware_Uninstalled.txt"}
else
{Write-output "VMware Tools Not Present" | Out-File -Encoding ascii -filepath "D:\log\folder\location\VMware_Not_Present.txt"}
}
#Write output log if VM
if($MachineType -eq "VM")
{Write-Output "Machine is virtual" | Out-File -Encoding ascii -filePath
"D:\log\folder\location\Virtual_Machine.txt"}
else
{Write-Output "Error" | Out-File -Encoding ascii -FilePath
"D:\log\folder\location\Error.txt"}
オープニング 'if'ステートメントがありません(前のステートメントは閉じています)。より標準的な書式を使用してみてください。そうすれば、あなたはすぐに飛び出します。 – briantist
こんにちはbriantist、見ていただきありがとうございます。正直言って私が知っているすべてのことが今のところ自分自身で教えられているので(私は秋にPSでクラスを受講しています)、より標準的なフォーマットがどんなものか分かりません。最初の*と書かれているときは、*が*の場合は2番目の*を意味しますか?物理的な場合はVMware Toolsの削除を実行し、ログ*セクションは書きますか?ありがとうございました。 – DieGeist