English 中文(简体)
PowerShell 远距离会议和范围问题: 指挥部似乎在当地运作。
原标题:PowerShell Remote sessions and scope question: Commands appear to run locally

这里有一份样本,试图在服务器上设立一个远程会议,然后利用海事委员会获得服务器全球导航卫星系统应用库的名单,并列出其名称:

    function Test-Remoting
    {
        [CmdletBinding()]
        param
        (    
        )
        begin
        {
            Enter-PSSession TestServer
            $appPools = Get-WmiObject -namespace "rootMicrosoftIISv2" -class "IIsApplicationPool" -Authentication 6
            $appPools | ForEach-Object {
                $appPool = $_;
                $appPool.Name
            }
            Exit-PSSession
        }    
    }

这项职能载于一份名为“试运行”的文件。 我打开了PowerShell,CD进入载有该档案的名录,将档案存放起来,并称其功能:

PS C:Usersmoskie> . .Test-Remoting.ps1
PS C:Usersmoskie> Test-Remoting

但是,这一说明的结果是我的 当地<>/em>机器和not上申请集合清单。 测试仪。

或者,如果我操作以下线路(即功能中的线路),则由电车速操作,Impem>do />获得遥远服务器上的机群名单:

PS C:Usersmoskie> Enter-PSSession TestServer
[TestServer]: PS C:> $appPools = Get-WmiObject -namespace "rootMicrosoftIISv2" -class "IIsApplicationPool" -Authentication 6
[TestServer]: PS C:> $appPools | ForEach-Object { $appPool = $_; $appPools.Name }
<a list of the names of the application pools on TestServer>
[TestServer]: PS C:>

我认为,关于动力船的恢复和范围,有一种概念是迷惑不解的。 谁能帮助解释这种行为?

最佳回答

我认为,进入/延伸-PSSession意味着更多的互动使用。 职业介绍所帮助:

SYNOPSIS
    Starts an interactive session with a remote computer.

• 以文字形式使用新的PSSession和Invoke-Command喜欢:

$session = New-PSSession server01
Invoke-Command -Session $session {hostname}
Remove-PSSession -Session $session

<>Update: a. 远距离使用Invoke-Command的文档Path参数。

icm server01 -FilePath C:userskeithmyscript.ps1 -arg 1,2

这将把该书复印到遥远的计算机服务器01,并在该台安装了所提供的参数。

问题回答

暂无回答




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签