Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Win32Shutdown通用故障_Powershell_Wmi_Vdi - Fatal编程技术网

Powershell Win32Shutdown通用故障

Powershell Win32Shutdown通用故障,powershell,wmi,vdi,Powershell,Wmi,Vdi,我正在编写一个脚本,该脚本将注销已处于断开连接状态超过10小时的VDI会话。除了最后一个障碍外,我已经设法把所有的事情都安排好了——实际上是被迫退出 ForEach($VDIlist中的桌面) { $win32OS=获取wmiobject win32_operatingsystem-ComputerName$desktop.'DNS Name'-EnableAllPrivileges 写入主机“正在关闭主机$Desktop.”DNS名称“” $win32OS.Win32Shutdown(4) }

我正在编写一个脚本,该脚本将注销已处于断开连接状态超过10小时的VDI会话。除了最后一个障碍外,我已经设法把所有的事情都安排好了——实际上是被迫退出

ForEach($VDIlist中的桌面)
{
$win32OS=获取wmiobject win32_operatingsystem-ComputerName$desktop.'DNS Name'-EnableAllPrivileges
写入主机“正在关闭主机$Desktop.”DNS名称“”
$win32OS.Win32Shutdown(4)
}    
这将导致以下错误

Exception calling "Win32Shutdown" : "Generic failure "
At line:1 char:1
+ $win32OS.win32shutdown(4)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WMIMethodException
当没有使用参数时,这似乎不会发生
$win32os.win32shutdown()
),但这也不会像我要求的那样强制注销

据我所知,
-EnableAllPrivileges
参数应允许远程注销,如果我有一个与VDI的实时PCoIP会话,它确实可以工作,我正试图关闭,但在断开连接状态下不工作。

有人能给我指出正确的方向吗?

仍然不能完全确定为什么第一个脚本会出现错误,但我已转而使用VMWare View内置的PowerCLI管理单元来产生相同的结果—只是更快、更高效

get-remotesession -state "Disconnected" | Where-Object {($_.duration -match 'Day' -or $_.duration -match '\d\d hours')} | Send-SessionLogoff
这将向Horizon view服务器查询任何具有“断开连接状态”的会话,然后它将过滤掉生命周期小于10小时的任何对象,并注销剩余的任何对象


这要求加载VMware View PowerCLI PSSnippets并将其连接到您的View连接断开。

您看到了吗?它提到您需要
SE_SHUTDOWN\u NAME
它还建议在同一WMI类上尝试
Win32ShutdownTracker
方法。因此,我个人会首先尝试使用
Enter PSSession
远程访问主机,列出我的权限(
whoami/priv
),然后尝试调用相同的wmi命令,看看是否可以这样做。@nohwnd是的,这是我一直使用的文档。我拥有域管理员权限,因此不会出现问题,我刚刚尝试了
Win32ShutdownTracker
,遇到了相同的问题。我已经求助于使用强制关机参数,因为这似乎是可行的,而且桌面无论如何都会刷新,因此这是相同的最终结果(尽管速度稍慢),我使用VMware View内置的“Powercli”使用替代命令解决了这一问题<代码>获取远程会话-状态为“断开连接”|其中对象{($\.duration-match'Day'-或$\.duration-match'\d\d hours')}|发送会话登录关闭