我有powershell脚本来获取交换用户,这个脚本从C#调用。这还会在临时目录中创建临时文件。但是当从c#调用时,Get-PSSession|Remove-PSSession
不会删除临时文件。但是,当从Powershell窗口执行脚本时,它会删除临时文件。
Function GetExchangeUsers($userName, $cred){
try{
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $ExSession -AllowClobber | Out-Null
$exchangeUsers=Get-MailBox -Filter '(RecipientTypeDetails -eq "UserMailBox")' | select UserPrincipalName,InPlaceHolds
return $exchangeUsers
}
finally{
get-module | Remove-Module
Get-PSSession|Out-File "F:\FinallyGetExchangeUsers.txt"
Get-PSSession|Remove-PSSession
Get-PSSession|Out-File "F:\AfterFinallyGetExchangeUsers.txt"
}
}
这里有什么问题?