Reputation: 995
Whatever value entered for $appPoolName always returns true for Test-Path when sent to the remote machine, even when no such pool exists. When run locally in powershell on those machines, the proper result is returned. PSRemote is verified to be enabled on the target machines.
$appPoolName = 'Abc123'
$scriptBlock = {
Import-Module WebAdministration
if (Test-Path IIS:\AppPools\$appPoolName) {
Write-Host "Already installed."
} else {
Write-Host "Installing..."
$appPool = New-Item –Path IIS:\AppPools\$using:appPoolName
$appPool | Set-ItemProperty -Name managedRuntimeVersion -Value 'v4.0'
}
}
Invoke-Command -ComputerName LT-CODE8 -ScriptBlock $scriptBlock
Why is this reporting true, or what steps can I take to further diagnose?
Upvotes: 1
Views: 688
Reputation: 703
I had this problem when I was running Powershell in VS Code. In ISE it always worked as expected.
Upvotes: 0
Reputation: 178
Probably enabling cred-ssp is needed on the remote machine. Please see this thread: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/3ea1ac5a-60f4-4ba1-9bdf-1119e2e5c896/testpath-fails-on-remote-computer-with-invokecommand?forum=ITCG
Upvotes: 0
Reputation: 10034
I think you missed the $using: on the first call of $appPoolname:
if (Test-Path IIS:\AppPools\$using:appPoolName) {
Upvotes: 1