PowerShell脚本模块不会返回任何信息

时间:2017-08-08 18:16:47

标签: powershell

我有以下模块:

Function Get-ProcessHash {
    param($ComputerName)

    $username = $ComputerName + '\localadm'
    $password = ConvertTo-SecureString 'supersecret' -AsPlainText -Force
    $cred = New-Object -typename System.Management.Automation.PSCredential -ArgumentList $username, $password

    Invoke-Command -ComputerName $ComputerName -Credential $cred -Authentication Negotiate -ScriptBlock {
        Get-Process * | Select-Object Id, Name, ProductVersion, Company, Path, @{l="SHA256";e={if ($_.Path -ne $null) { (Get-FileHash $_.Path).Hash}}}
    }
}

此脚本模块位于C:\Users\<username>\Documents\WindowsPowerShell\Modules\SuperModule\SuperModule.psm1。我可以通过Get-Command -Module SuperModule看到它的功能。如果我在函数外部手动运行脚本的内容,它将工作并返回所有值,但是当我尝试将函数作为PS C:\Users\<username>\Documents\Scripts> Get-ProcessHash US0001运行时,它不返回任何内容。

凭证有效,我可以在模块外部执行脚本并且它可以正常工作。

1 个答案:

答案 0 :(得分:0)

Matt在评论中说,解决方案很简单:

“您是否在加载此模块时对其进行了更改?如果您关闭所有活动的PowerShell会话并重试,那么您的问题是否相同?”