模仿';来源';powershell中的命令

模仿';来源';powershell中的命令,powershell,Powershell,我试图在powershell中模仿bash的命令。其目的是对mymicrosoft.powershell\u profile.psl进行任何更改,并将其源代码转换为powershell的现有实例 以下命令在命令行中工作 $profile_content = [string]::join([environment]::newline,(get-content $profile)) invoke-expression $profile_content 一切都好;我在microsoft.powers

我试图在powershell中模仿bash的命令。其目的是对my
microsoft.powershell\u profile.psl进行任何更改,并将其源代码转换为powershell的现有实例

以下命令在命令行中工作

$profile_content = [string]::join([environment]::newline,(get-content $profile))
invoke-expression $profile_content
一切都好;我在microsoft.powershell\u profile.psl中输入了相同的代码,但它不起作用

function source{
        $profile_content = [string]::join([environment]::newline,(get-content $args[0]))
        invoke-expression $profile_content
}

我是否忽略了什么?

请尝试将您的
Microsoft.PowerShell\u profile.ps1
更改为如下所示:

function source{
        $profile_content = [string]::join([environment]::newline,(get-content $args[0]))
        invoke-expression $profile_content
}

source $profile

基本上,您不能只定义函数,还需要在文件中调用它但是,函数的设置方式将导致无限循环。用其他内容替换
函数源()

尝试将
Microsoft.PowerShell\u profile.ps1
更改为如下所示:

function source{
        $profile_content = [string]::join([environment]::newline,(get-content $args[0]))
        invoke-expression $profile_content
}

source $profile

基本上,您不能只定义函数,还需要在文件中调用它但是,函数的设置方式将导致无限循环。用其他内容替换您的
函数源()

您想要的已内置到PowerShell中:

. C:\path\to\some.ps1
见:

网点采购运营商

在当前作用域中运行脚本,以便, 脚本创建的别名和变量将添加到当前 范围

. c:\scripts.sample.ps1

您想要的已内置到PowerShell中:

. C:\path\to\some.ps1
见:

网点采购运营商

在当前作用域中运行脚本,以便, 脚本创建的别名和变量将添加到当前 范围

. c:\scripts.sample.ps1

您能否共享作为
$profile
$args[0]
传递的值?$profile来自powershell环境。我的系统中的值为C:\Users\\Documents\WindowsPowerShell\Microsoft.PowerShell\U profile.ps1。我调用source命令作为“source$profile”更新:试图以错误的方式重新发明轮子。更好地使用回答中的“.”。您能否共享作为
$profile
$args[0]
传递的值?$profile来自powershell环境。我的系统中的值为C:\Users\\Documents\WindowsPowerShell\Microsoft.PowerShell\U profile.ps1。我调用source命令作为“source$profile”更新:试图以错误的方式重新发明轮子。最好使用“.”正如我所回答的。我不太明白。为什么要将对函数的调用作为函数定义的一部分包含在“Microsoft.PowerShell_profile.ps1”中?我将从命令行调用该函数。为什么是无限循环?这两行代码在命令行中工作,我不太明白。为什么要将对函数的调用作为函数定义的一部分包含在“Microsoft.PowerShell_profile.ps1”中?我将从命令行调用该函数。为什么是无限循环?这两行代码在命令行中工作。