我需要创建一个清除远程计算机上Lync缓存的脚本。为此,我需要关闭Outlook和Lync,如果它们是打开的,然后清除两个文件夹,同时删除另一个。以下是我到目前为止的情况:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$computer = [Microsoft.VisualBasic.Interaction]::InputBox("Which computer do you wish to clear the Lync cache for?", "Computer", "$env:computername")
$username = Get-WMIObject -class Win32_ComputerSystem -ComputerName $computer | select username
$RSA = "C$\Users\$username\AppData\Roaming\Microsoft\Crypto\RSA"
$Tracing = "C$\Users\$username\AppData\Local\Microsoft\Office\15.0\Lync\Tracing"
$SIP = "C$\Users\$username\AppData\Local\Microsoft\Office\15.0\Lync"
(Get-WmiObject Win32_Process -ComputerName $computer | ?{ $_.ProcessName -match "Outlook" }).Terminate()
(Get-WmiObject Win32_Process -ComputerName $computer | ?{ $_.ProcessName -match "Lync" }).Terminate()
(Get-WmiObject Win32_Process -ComputerName $computer | ?{ $_.ProcessName -match "Communicator" }).Terminate()
start-sleep -s 3
Get-ChildItem -path \\$computer\$RSA -include * | Remove-Item -recurse -force
Get-ChildItem -path \\$computer\$Tracing -include * | Remove-Item -recurse
Remove-Item -path \\$computer\$SIP\*sip* -recurse -force
脚本会根据需要关闭程序,但它似乎对文件夹没有任何作用。我得到的唯一错误如下:
You cannot call a method on a null-valued expression.
At C:\Users\*myusername*\Desktop\Personal Powershell scripts\Clear Lync cache.ps1:10 char:1
+ (Get-WmiObject Win32_Process -ComputerName $computer | ?{ $_.ProcessName -match ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\*myusername*\Desktop\Personal Powershell scripts\Clear Lync cache.ps1:11 char:1
+ (Get-WmiObject Win32_Process -ComputerName $computer | ?{ $_.ProcessName -match ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\*myusername*\Desktop\Personal Powershell scripts\Clear Lync cache.ps1:12 char:1
+ (Get-WmiObject Win32_Process -ComputerName $computer | ?{ $_.ProcessName -match ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
ISE以管理员身份打开。我拥有该域的管理员权限以及相关文件夹。谁能看到我哪里出错?