相关疑难解决方法(0)

Powershell:使用PS 5类时无法找到类型

我在PS中使用WinSCP Powershell Assembly.在其中一种方法中,我使用的是WinSCP中的各种类型.

只要我已经添加了程序集,这就可以正常工作 - 但是,由于Powershell在使用类时读取脚本的方式(我假设?),在加载程序集之前会抛出错误.

实际上,即使我将Write-Host放在顶部,它也不会加载.

在解析文件的其余部分之前,有没有办法强制运行某些东西?

Transfer() {
    $this.Logger = [Logger]::new()
    try {

        Add-Type -Path $this.Paths.WinSCP            
        $ConnectionType = $this.FtpSettings.Protocol.ToString()
        $SessionOptions = New-Object WinSCP.SessionOptions -Property @{
            Protocol = [WinSCP.Protocol]::$ConnectionType
            HostName = $this.FtpSettings.Server
            UserName = $this.FtpSettings.Username
            Password = $this.FtpSettings.Password
        }
Run Code Online (Sandbox Code Playgroud)

Protocol = [WinSCP.Protocol] :: $ ConnectionType

无法找到类型[WinSCP.Protocol].

powershell add-type winscp-net

8
推荐指数
2
解决办法
3741
查看次数

你怎么称呼这些?[数组][字符串][整数]

这些叫什么?在 powershell 中编写脚本时,我可以使用它们来设置或转换变量的数据类型,但是这个术语是什么?这些有官方文档吗?

例子:

$var = @("hello","world")
If ($var -is [array]) { write-host "$var is an array" }
Run Code Online (Sandbox Code Playgroud)

.net powershell terminology

3
推荐指数
1
解决办法
100
查看次数

标签 统计

powershell ×2

.net ×1

add-type ×1

terminology ×1

winscp-net ×1