Cmdlet below works normally, but does nothing within a do
& switch
statement in code block at bottom? Debugging in ISE doesn't provide any help. Removing | Select-Object
does make it function, but produces too much info. Removing -CimSession $hostname
does make it function. So issue seems related to the remote PC and/or SELECT statement.
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 '')
- Same issue with this cmdlet:
{Get-WMIObject Win32_UserProfile -ComputerName $hostname | Select-Object -Property LocalPath,LastUseTime}
- Works, but is spaced funny:
{Get-WMIObject Win32_UserProfile -ComputerName $hostname | Format-List LocalPath, LastUseTime}
- Works, but is spaced funny & has weird runspaceID item:
{Invoke-Command -ComputerName $hostname -HideComputerName -ScriptBlock {Get-WMIObject Win32_UserProfile | Select-Object LocalPath, LastUseTime}}