Powershell passing variables to remote script

后端 未结 1 1168
南笙
南笙 2020-12-21 10:38

I have the following cmd file:-

PowerShell.exe -noexit E:\\wwwroot\\domains\\processes\\AddDirectory.ps1 -Param testdomain.co.uk

which goes

相关标签:
1条回答
  • 2020-12-21 11:40

    You need to use a param block in the script, the argument you pass to the file will be assign to $domainName and you will use it to pass the value to the scriptblock :

    PowerShell.exe -noexit E:\wwwroot\domains\processes\AddDirectory.ps1 testdomain.co.uk
    
    
    # script file
    
    param($domainName)
    
    $script = {
        Param($Param1)
    
        ...
        $domain = $Param1
        ...   
    }
    
    $Session = New-PSSession -ComputerName 192.168.0.25
    Invoke-Command -Session $Session -ScriptBlock $script -ArgumentList $domainName
    
    0 讨论(0)
提交回复
热议问题