Powershell pasando variables a un script remoto
Tengo el siguiente archivo cmd: -
PowerShell.exe -noexit E:\wwwroot\domains\processes\AddDirectory.ps1 -Param testdomain.co.uk
que pasa por: -
$Session = New-PSSession -ComputerName 192.168.0.25
$script = {
Param($Param1)
set-executionpolicy unrestricted -force
# Set Variables
$domain = $Param1
$sitepath = "e:\domains\" + $domain
# Check for physical path
if (-not (Test-Path -path $sitePath))
{
New-Item -Path $sitepath -type directory
New-Item -Path $sitepath\wwwroot -type directory
}
set-executionpolicy restricted -force
}
Invoke-Command -Session $Session -ScriptBlock $script
Pero solo corre pero no hace nada.
Si declaro la variable $ domain como $ domain = 'testdomain.co.uk' funciona, pero no quiere pasar a través de la var desde el archivo cmd. ¿Qué estoy haciendo mal? He intentado ponerlo en Invoke-Command como -ArgumentsList - $ Param1 pero eso tampoco funciona ...
Cualquier idea bien recibida
Gracias paul
Actualización: he actualizado mi código como se muestra a continuación, pero tengo el mismo problema:
param($domainName)
$script = {
Param($Param1)
set-executionpolicy unrestricted -force
# Set Variables
$domain = $Param1
$sitepath = "e:\domains\" + $domain
# Check for physical path
if (-not (Test-Path -path $sitePath))
{
New-Item -Path $sitepath -type directory
New-Item -Path $sitepath\wwwroot -type directory
New-Item -Path $sitepath\db -type directory
New-Item -Path $sitepath\stats -type directory
}
set-executionpolicy restricted -force
}
$Session = New-PSSession -ComputerName 192.168.0.25
Invoke-Command -Session $Session -ScriptBlock $script -ArgumentList $domainName