第一个短代码,然后问题
$session = New-PSSession -ComputerName someServer
$servicesList = "Service1", "Service2", "Service3"
Invoke-Command -ScriptBlock {
Param ($newServicesList)
Write-Host $newServicesList
} -ArgumentList $servicesList -Session $session
Remove-PSSession $session
Run Code Online (Sandbox Code Playgroud)
问题是为什么Invoke-Command块中的Write-Host只给出这个输出?
Service1
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答
I have a question about delegate in this code, I add three method to delegate. There're return a string. In the line
string delOut = del("Beer");
to my valuable delOut delegate assignet this "Length : 4"
How can I collect all strings that methods in delegate returns ?
public class NaForum
{
public delegate string MyDelegate(string s);
public void TestDel()
{
MyDelegate del = s => s.ToLower();
del += s => s.ToUpper();
del += s => string.Format("Length : {0}", s.Length); …Run Code Online (Sandbox Code Playgroud) 我从NewWebServiceProxy cmdlet捕获异常时遇到问题
try {
$myService = New-WebServiceProxy -Uri "http://localhost/someservice.svc"
}
catch {
Write-Log ([string]::Format("Error : {0}", $_.Exception.Message))
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到了这个未处理的异常:New-WebServiceProxy:
请求失败,HTTP状态为404:未找到.在C:\ Users\SomeUser\AppData\Local\Temp\d052b604-38ad-4827-b952-4ebc66e79c69.ps1:2 char:18 + $ myService = New-WebServiceProxy -Uri
"http://localhost/someservice.svc"+ ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CategoryInfo:ObjectNotFound :(http://localhost/someservice.svc:Uri)[New-WebServiceProxy],WebExc eption + FullyQualifiedErrorId:WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
有人可能会问我为什么尝试捕获不捕获此异常?谢谢你的任何aswer
powershell web-services exception-handling exception new-webserviceproxy