0
こんにちは私は以下のスクリプトブロックを使用していて、テストパス中に$Null
という変数ローカルフォルダを渡しました。あなたは、あなたのコード内で宣言した。存在しないとして、あなたが-Session $のPSSessionを必要としない(あなたはより多くの背景を提供したいと考えていない限り)私はあなたの例では、ここでPowershellで変数付きの問題
$ScriptBlockDir = {
Param (
[string]$samAccountName
)
If ($Env:ComputerName -eq 'fileserver101')
{
$LocalFolderPath = 'H:\Users'
}
Else
{
$LocalFolderPath = 'D:\Users'
}
If (-not (test-path -Path "$LocalFolderPath\$samAccountName"))
{
Try
{
LogEntry "New Home Drive Folder"
New-Item -Path $LocalFolderPath -Name $samAccountName -ItemType Directory >$Null
return 1
}
catch
{
Write-Host "Failed with error"
return -1
}
}
Write-Host "already exists"
Return 0
}
$result = Invoke-Command -Session $PSSession -ScriptBlock $ScriptBlockDir -ArgumentList $samAccountName