2016-10-31 1 views
6

현재 질문에 영향을주지 않아야하는 이유 때문에 명령을 사용하지 않고 다른 PowerShell 인스턴스에서 명령 외부의 매개 변수와 정의를 사용하여 스크립트를 실행해야합니다. PSSession, 백그라운드 작업 또는 파일 (PSSession, 백그라운드 작업 및 .ps1 파일에 대한 예제를 작업하고 있으며이를 수행 할 작업을 대체 할 수 있음을 알고 있지만 powershell.exe -Command과 함께 작업 예제가 필요함).powershell.exe와 -Command with Scriptblock 및 매개 변수를 사용하는 방법

나는 help for powershell.exe을 보았고, 내가하려는 일을 지원해야하지만, 필요한 모든 것 (스크립트 정의와 명령 매개 변수가 명령 외부에 있음)을 사용할 수 없다. 작업 예를 들어

내가 가지고있는 더 나은

$abc = powershell.exe -WindowStyle Hidden -NonInteractive -Command {Invoke-Command -ScriptBlock { 
param($a1,$a2) 
$a1*6 
$a2*5} -Argumentlist @($args[0],$args[1])} -args @(8,'abc') 

과 :

$abc = powershell.exe -WindowStyle Hidden -NonInteractive -Command {Invoke-Command -ScriptBlock { 
    param($a1,$a2) 
    $a1*6 
    $a2*5} -Argumentlist @(8,'abc')} 

나는 적어도 같은 명령 외부 -ArgumentList를 이동 할 수 있어야합니다

$script={ 
param($a1,$a2) 
$a1*6 
$a2*5} 
[email protected](8,'abc') 
$abc = powershell.exe -WindowStyle Hidden -NonInteractive -Command $script -args $args 

나는 다음과 같은 비슷한 질문을 이미 보았지만, 나는 무엇을 발견 할 수 없었다. eeded :

+0

사용 사례는 무엇입니까? –

+0

'-WindowStyle Hidden'을 제거하십시오. – PetSerAl

+1

PowerShell에서 실행하는 것처럼 보입니다. 그렇다면 왜 단순히'Invoke-Command' 대신'powershell.exe -Command'가 필요하다고 생각합니까? –

답변

0

이 내가 원래 스크립트에 몇 가지를 추가 및 $ Z에 $ 인수를 변경하고 작업을 보였다 도움이되는지 확실하지.

$script={ 
param($a1 =1 ,$a2 = 2) 
$a1*6 
$a2*5 
test-connection -Count 2 www.google.com 
Write-Output $a1 
Write-Output $a2 
} 
[email protected](8,'abc') 
$abc = powershell.exe -WindowStyle Hidden -NonInteractive -Command $script -args $z 

$ abc 방송

48 
abcabcabcabcabc 

PSComputerName     : ok 
IPV4Address     :1.1.1.4 
IPV6Address     : 
__GENUS      : 2 
__CLASS      : Win32_PingStatus 
__SUPERCLASS     : 
__DYNASTY      : Win32_PingStatus 
__RELPATH      : Win32_PingStatus.Address="www.google.com",BufferSize=32,NoFragmentation=FALSE,RecordRoute=0,ResolveAddressNames=FALSE,SourceRou 
           te="",SourceRouteType=0,Timeout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0 
__PROPERTY_COUNT    : 24 
__DERIVATION     : {} 
__SERVER      : ok 
__NAMESPACE     : root\cimv2 
__PATH       : \\ok\root\cimv2:Win32_PingStatus.Address="www.google.com",BufferSize=32,NoFragmentation=FALSE,RecordRoute=0,ResolveAddressName 
           s=FALSE,SourceRoute="",SourceRouteType=0,Timeout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0 
Address      : www.google.com 
BufferSize      : 32 
NoFragmentation    : False 
PrimaryAddressResolutionStatus : 0 
ProtocolAddress    :1.1.1.4 
ProtocolAddressResolved  : 
RecordRoute     : 0 
ReplyInconsistency    : False 
ReplySize      : 32 
ResolveAddressNames   : False 
ResponseTime     : 19 
ResponseTimeToLive    : 252 
RouteRecord     : 
RouteRecordResolved   : 
SourceRoute     : 
SourceRouteType    : 0 
StatusCode      : 0 
Timeout      : 4000 
TimeStampRecord    : 
TimeStampRecordAddress   : 
TimeStampRecordAddressResolved : 
TimestampRoute     : 0 
TimeToLive      : 80 
TypeofService     : 0 


PSComputerName     : ok 
IPV4Address     :1.1.1.4 
IPV6Address     : 
__GENUS      : 2 
__CLASS      : Win32_PingStatus 
__SUPERCLASS     : 
__DYNASTY      : Win32_PingStatus 
__RELPATH      : Win32_PingStatus.Address="www.google.com",BufferSize=32,NoFragmentation=FALSE,RecordRoute=0,ResolveAddressNames=FALSE,SourceRou 
           te="",SourceRouteType=0,Timeout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0 
__PROPERTY_COUNT    : 24 
__DERIVATION     : {} 
__SERVER      : ok 
__NAMESPACE     : root\cimv2 
__PATH       : \\ok\root\cimv2:Win32_PingStatus.Address="www.google.com",BufferSize=32,NoFragmentation=FALSE,RecordRoute=0,ResolveAddressName 
           s=FALSE,SourceRoute="",SourceRouteType=0,Timeout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0 
Address      : www.google.com 
BufferSize      : 32 
NoFragmentation    : False 
PrimaryAddressResolutionStatus : 0 
ProtocolAddress    :1.1.1.4 
ProtocolAddressResolved  : 
RecordRoute     : 0 
ReplyInconsistency    : False 
ReplySize      : 32 
ResolveAddressNames   : False 
ResponseTime     : 21 
ResponseTimeToLive    : 252 
RouteRecord     : 
RouteRecordResolved   : 
SourceRoute     : 
SourceRouteType    : 0 
StatusCode      : 0 
Timeout      : 4000 
TimeStampRecord    : 
TimeStampRecordAddress   : 
TimeStampRecordAddressResolved : 
TimestampRoute     : 0 
TimeToLive      : 80 
TypeofService     : 0 

8 
abc