私は次のcmdファイルを持っています:-
PowerShell.exe -noexit E:\wwwroot\domains\processes\AddDirectory.ps1 -Param testdomain.co.uk
これは次のようになります:-
$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
しかし、それは実行されるだけで、何もしません。
$domain変数を$domain='testdomain.co.uk'として宣言すると、機能しますが、cmdファイルから変数を渡したくありません。私は何が間違っているのですか?Invoke-Commandに-ArgumentsList-$Param1として配置しようとしましたが、それも機能しません。
どんなアイデアも大歓迎
ありがとうポール
更新-以下のようにコードを更新しましたが、同じ問題が発生します:-
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