Looking to write api events to the Windows Event log using powershell and looking for guidance on how to expose older powershell version cmdlets to the PSU api runspace. When i run the api i put a wait-debugger in it to troubleshoot why it was failing and noticed from within that runspace i only see Powershell 7 cmdlets which does not include the one i need. When i exit from the pshost process and look for the command it works fine on the server. I’ve run get-command from within the pshost process and outside for comparison.
Output:
IN PSHOST process:
[servername]: [Process:5920]: PS C:\Users\Server\Documents> Get-command event | where {_.commandType -like "Cmdlet" -and _.Name -like "event}
Cmdlet Get-Event 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Get-EventSubscriber 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Get-WinEvent 7.0.0.0 Microsoft.PowerShell.Diagnostics
Cmdlet New-Event 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet New-WinEvent 7.0.0.0 Microsoft.PowerShell.Diagnostics
Cmdlet Register-CimIndicationEvent 7.0.0.0 CimCmdlets
Cmdlet Register-EngineEvent 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Register-ObjectEvent 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Remove-Event 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Unregister-Event 7.0.0.0 Microsoft.PowerShell.Utility
Cmdlet Wait-Event 7.0.0.0 Microsoft.PowerShell.Utility
From normal pssession remoting:
[servername]: PS C:\Users\Server\Documents> Get-command event | where {_.commandType -like "Cmdlet" -and _.Name -like "event}
Cmdlet Clear-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Event 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Get-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Get-EventSubscriber 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Get-WinEvent 3.0.0.0 Microsoft.PowerShell.Diagnostics
Cmdlet Limit-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet New-Event 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet New-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet New-WinEvent 3.0.0.0 Microsoft.PowerShell.Diagnostics
Cmdlet Register-CimIndicationEvent 1.0.0.0 CimCmdlets
Cmdlet Register-EngineEvent 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Register-ObjectEvent 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Register-WmiEvent 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Remove-Event 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Remove-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Show-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Unregister-Event 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Wait-Event 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Write-EventLog 3.1.0.0 Microsoft.PowerShell.Management