質問

I need to add an application pool remotely and I was trying to use the following:

$script = {
    Import-Module WebAdministration;
    New-Item IIS:\AppPools\$IRTPoolName;
}
Invoke-Command -ComputerName $targetName -ScriptBlock $script -credential $cred -UseSSL

The problem is that once I run it I get a prompt with:
type:
I don't have any problems with authentication and I can invoke other commands like a simple dir but not that one. Any thoughts?

役に立ちましたか?

解決

The new-item cmdlet is asking you to specify a type, because it doesn't know what $IRTPoolName is.

Invoke-Command -ComputerName $targetName -ScriptBlock {
Param($IRTPoolName)
    Import-Module WebAdministration
    New-Item IIS:\AppPools\$IRTPoolName
} -ArgumentList $IRTPoolName -credential $cred -UseSSL

http://www.powershellmagazine.com/2013/01/23/pstip-passing-local-variables-to-a-remote-session-in-powershell-3-0/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top