Powershell v4:将添加的类型发送到远程调用命令
我有一个文件Models.cs,其中包含常规的C#类,在我的主脚本上我添加了类型,但我还需要在远程机器上运行的脚本上使用Invoke命令使用相同的模型Powershell v4:将添加的类型发送到远程调用命令,powershell,remote-server,powershell-4.0,Powershell,Remote Server,Powershell 4.0,我有一个文件Models.cs,其中包含常规的C#类,在我的主脚本上我添加了类型,但我还需要在远程机器上运行的脚本上使用Invoke命令使用相同的模型 $Server = Invoke-Command -ComputerName $ip` -ConfigurationName ConfigurationExmpl` -Credential $credential -filepath "path/to/script.ps1" 我知道我能做到 Add-Type -TypeDe
$Server = Invoke-Command -ComputerName $ip`
-ConfigurationName ConfigurationExmpl`
-Credential $credential -filepath "path/to/script.ps1"
我知道我能做到
Add-Type -TypeDefinition @"
public class ServerModel
{
public string Name;
public string Hostname;
public string Ip;
public string OperatingSystem;
}"
在我要发送到远程的脚本中,但是我会在多个地方定义相同的模型,我希望它们都在models.cs中
是否可以将Models.cs文件与要执行的脚本一起传递,然后尝试从同一目录中读取,或者通过其他方式执行此操作?展开Mathias的评论;如果您能够通过UNC路径调用脚本,请将Models.cs放在同一文件夹中,并让脚本也调用它(为了安全起见也可以通过UNC路径)为什么不首先包括
Add Type
调用script.ps1
,如果它依赖于它?但它不是将在与脚本存储位置不同的位置执行吗?如果我在script.ps1中添加Type,它将尝试在远程计算机中查找Models.cs,因为它是在那里执行的。我将该脚本从本地计算机发送到远程计算机并在那里执行。脚本未存储在远程计算机上。