##質問
powershellで、関数の値渡しを行おうとしているのですが、
以下エラーが出てしまいます。
##やろうとしていること
複数の宛先端末(windows)にpingを打って、生きていたらpsexecでゴニョゴニョ
###発生している問題・エラーメッセージ
引数の型をSystem.voidにすることはできません。
発生場所 C:sourcepath**.ps1:33 文字7
-
$out=mypsexec($myarg)
###該当のソースコード
$pinfo = New-Object System.Diagnostics.ProcessStartInfo $pcname = (Get-Content list.txt) -as [string[]] function mypsexec($in){ $pinfo.FileName ="PsExec.exe" $pinfo.RedirectStandardError = $true $pinfo.RedirectStandardOutput = $true $pinfo.UseShellExecute = $false $pinfo.CreateNoWindow = $True $pinfo.Arguments = $in $p = New-Object System.Diagnostics.Process $p.StartInfo = $pinfo [void]$p.Start() | Out-Null $stdout="" while (!$p.HasExited){ $line = $p.StandardOutput.ReadLine() $stdout += $line + "`n" } [void]$p.WaitForExit() [void]$p.Close() [void]$p.Dispose() return $stdout } for($i = 0; $i -lt $pcname.Count; $i++) { $pingAlive = @(Test-Connection -ComputerName $pcname[$i] -Quiet -count 1 ) if ($pingAlive -eq $True) { Write-Host ($pcname[$i] ) $myarg="` \\" + $pcname[$i] + "` -u` admin` -p` ****** cmd.exe` /c` type` %windir%\system32\drivers\etc\hosts" $out=mypsexec($myarg) if ([String]::IsNullOrEmpty($out) -eq $True){ echo "can not get hosts. nothing to do" }else{ //ゴニョゴニョ } } } }
###試したこと
デバッガーを起動しステップ実行。$myargに文字は入っている。
gettypeを実行したところ$myargはsystem.objectになっている
###補足情報(言語/FW/ツール等のバージョンなど)
os:windows7 SP1
psversion:3.0
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/01 03:11 編集
2016/08/02 01:27
2016/08/02 02:10
2016/08/02 02:20
2016/08/08 04:15
2016/08/08 04:44