Powershell 术语';编写PSFMessage';无法识别为cmdlet、函数、脚本文件或可操作程序的名称
我正在尝试获取虚拟机名称以用于日志记录Powershell 术语';编写PSFMessage';无法识别为cmdlet、函数、脚本文件或可操作程序的名称,powershell,Powershell,我正在尝试获取虚拟机名称以用于日志记录 Set-PSFLoggingProvider -Name logfile -Enabled $true -FilePath 'C:\PDS\++Scripts++\++logs++\replication_logs.log' $Hosts = "server01","server02" ForEach ($Server in $Hosts){ Write-Host 'Primary Server: '$Server $VMName
Set-PSFLoggingProvider -Name logfile -Enabled $true -FilePath 'C:\PDS\++Scripts++\++logs++\replication_logs.log'
$Hosts = "server01","server02"
ForEach ($Server in $Hosts){
Write-Host 'Primary Server: '$Server
$VMName
Invoke-Command -ComputerName $Server {
$FailedReplicas = Get-VMReplication | Where{$_.Health -EQ 'Normal'}
ForEach ($VM in $FailedReplicas){
$VMName = $VM.Name
Write-Host 'Virtual Machine: '$VMName
try{
Resume-VMReplication $VMName -Resynchronize
Write-Host 'Successfully resynched ' $VMName
Write-PSFMessage -Level Important -Message 'Successfully resynched ' $VMName -Tag 'Success'
}
catch{
Write-PSFMessage -Level Warning -Message 'Could not resync ' $VMName -Tag 'Failure' -ErrorRecord $_
}
}
}
}
pause
当我运行上面的代码时,我得到了这个错误
术语“Write PSFMessage”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。写入PSFMessage的模块是什么?我认为这不是微软的标准cmdlet。在这种情况下,您需要先在远程服务器上导入模块,然后才能使用它…我发现Write PSFMessage来自Powershell Gallery的PSFramework。你安装了这个模块吗?(Install Module-Name PSFramework)猜测该模块可能存在,因为
Set PSFLoggingProvider
来自同一位置。也许他们有一个较旧的版本存在于编写PSFMessage
之前。至少它不起作用,因为您的PowerShell中不存在该cmdletsession@T-我就像@Mike说的,它来自PSFramework,是的,我已经安装了Module-Name PSFramework
@Matt是的,模块存在,但如何使其在当前会话中可用,因为我甚至在文件顶部导入了模块PSFramework
,导入模块
必须位于调用命令
的脚本块中
$Hosts = "server01","server02"
ForEach ($Server in $Hosts){
Write-Host 'Primary Server: '$Server
$VMName
try {
Invoke-Command -ComputerName $Server -ScriptBlock {
Import-module PSFramework
$logPath = "\\x.x.x.123\C$\PDS\++Scripts++\++logs++\replication_logs.log"
Set-PSFLoggingProvider -Name logfile -Enabled $true -FilePath $logPath
$FailedReplicas = Get-VMReplication | Where{$_.Health -EQ 'Critical'}
ForEach ($VM in $FailedReplicas){
$VMName = $VM.Name
Write-Host 'Virtual Machine: '$VMName
Resume-VMReplication $VMName -Resynchronize
Write-Host 'Successfully resynched ' $VMName
Write-PSFMessage -Level Important -Message 'Successfully resynched' -Target $VMName -Tag 'Success'
}
}
} catch {
Write-PSFMessage -Level Warning -Message 'Could not resync ' -Tag 'Failure' -ErrorRecord $_
}
}
pause