'get-ciminstance win32_userprofile -CimSession | select' WITHIN DO & SWITCH 语句不起作用

问题描述

下面的 Cmdlet 工作正常,但在底部代码块的 do & switch 语句中没有任何作用?在 ISE 中调试不提供任何帮助。删除 | Select-Object 确实使它起作用,但会产生太多信息。删除 -CimSession $hostname 确实使它起作用。所以问题似乎与远程 PC 和/或 SELECT 语句有关。

Get-CimInstance Win32_UserProfile -CimSession $hostname | Select-Object -Property LocalPath,LastUseTime

function Show-Menu {
    Write-Host "
    1)Option A
    2)Option B
    3)User Profiles of Remote PC
    "}
DO {Show-Menu
    $UserChoice = Read-Host "Enter # of tool you want to run"
    $hostname=Read-Host "enter hostname"
    switch ($UserChoice) {
        1 {'You choose opt1'}
        2 {'You choose opt2'}
        3 {Get-CimInstance Win32_UserProfile -CimSession $hostname | Select-Object -Property LocalPath,LastUseTime}
   }
} UNTIL ($hostname -eq '')
  • 此 cmdlet 存在相同问题:{Get-WMIObject Win32_UserProfile -ComputerName $hostname | Select-Object -Property LocalPath,LastUseTime}
  • 有效,但间隔有趣:{Get-WMIObject Win32_UserProfile -ComputerName $hostname | Format-List LocalPath,LastUseTime}
  • 有效,但间隔有趣且具有奇怪的 runspaceID 项目:{Invoke-Command -ComputerName $hostname -HideComputerName -ScriptBlock {Get-WMIObject Win32_UserProfile | Select-Object LocalPath,LastUseTime}}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)