我正在尝试在SQL Server中执行以下PowerShell查询
xp_cmdshell "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"
执行此操作后,出现错误:
无法将“ get-WmiObject”识别为内部或外部命令,可操作程序或批处理文件。
我想在所有SQL Server中执行此命令。它已在SQL Server 2008上执行,但在SQL Server 2012上,由于版本或未安装某些PowerShell组件而引发该错误。
您能否请看一下代码并让我知道
尝试:
xp_cmdshell 'PowerShell.exe -noprofile -command "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"'
如果这不起作用,请PowerShell
使用管理员权限登录到服务器。键入Get-ExecutionPolicy
并检查执行策略是否设置为“无限制”。如果不是,请输入以下内容,然后输入“ A”(对所有人是):
Set-ExecutionPolicy Unrestricted
如果仍然无法进行,请尝试至少升级至PowerShell V3
。但是,如果这不可能,您可以尝试使用以下方法修复损坏的PowerShell V2
WMI存储库:
winmgmt /verifyrepository
如果发现存储库不一致,请运行Winmgmt /salvagerepository
并Winmgmt /resetrepository
在每次之后进行验证。如果仍然不一致,请尝试以下步骤:
Task Manager
>>服务>>打开服务>>Windows Management Instrumentation
服务,然后将启动类型更改为Manual
。停止WMI服务:
net stop winmgmt
将存储库文件夹(C:\Windows\System32\wbem\Repository
)重命名为其他“ Repository_OLD”。
启动WMI服务:
net start winmgmt
将服务设置回自动启动。
失败重新注册所有,然后使用以下脚本在目录中dlls
重新编译,然后重新启动。.mofs
Wbem
.bat
@echo off
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in (‘dir /b *.dll’) do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /regserver
sc config winmgmt start= auto
net start winmgmt
for /f %%s in (‘dir /s /b *.mof *.mfl’) do mofcomp %%s
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句