2016-10-31 9 views
6

Geçerli soruyu etkilememem gerekçeleri nedeniyle, komut dosyası dışında, komutun tanımı ve parametreleriyle, farklı bir PowerShell örneğinin içinde, kullanmadan kullanmam gerekir. PSSessions, arkaplan işleri veya dosyaları (PSSession, arkaplan işleri ve .ps1 dosyaları için çalışma örneklerine sahibim ve yapmaya çalıştığım şeylerin yerini alabileceğinin farkındayım, ancak powershell.exe -Command ile de bir çalışma örneğine ihtiyacım var).powershell.exe with -Command komut dosyası ve parametreleri kullanarak nasıl kullanılır

help for powershell.exe'a baktım ve ne yapmaya çalıştığımı desteklemeli, ancak ihtiyacım olan herşeyle (komutun tanımı ve komut dışındaki parametreler) çalışamıyorum. Çalışan bir örnek olarak

Ben: var daha iyi

$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') 

ve:

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

Ben en azından gibi komuta dışında -ArgumentList hareket edebilmesi gerekir

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

Aşağıdaki benzer sorulara zaten baktım, ama n neyi bulamadım eeded:

+0

Kullanım durumunuz nedir? –

+0

'-WindowStyle Hidden' öğesini kaldır. – PetSerAl

+1

Bunu PowerShell içinden çalıştırıyor gibi görüyorsunuz, o zaman neden 'Invoke-Command' komutunu kullanmak yerine' powershell.exe -Command' 'a ihtiyacınız olduğunu düşünüyorsunuz? –

cevap

0

bu ben orijinal senaryoya bir şeyler ekledi ve $ z $ args değiştirdi ve işe gibiydi yardımcı emin değilim.

$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 
İlgili konular