$command='az vm run-command invoke --command-id RunPowerShellScript --name '.$vm_name.' --resource-group '.$resource_group.' --scripts @C:/Users/Get-ULogged_In.ps1; ';
在此命令中,我需要通过传递 2 个参数从 Get-ULogged_In.ps1 文件中调用一个函数。
这是脚本文件
function Get-ULogged_In([string]$After,[string]$Before)
{
$BeforeLog = (get-Date $Before)
$AfterLog = (get-Date $After)
$EventDataCollector_1 = get-winevent -logname Microsoft-Windows-TerminalServices-LocalSessionManager/Operational | where {$_.TimeCreated -gt $AfterLog -and $_.TimeCreated -lt $BeforeLog -and ($_.Id -eq "21") }
foreach($DataCollected_1 in $EventDataCollector_1)
{
$UserLogged_1 = $DataCollected_1.Message.Split([environment]::NewLine)
$UserLogged_1 = $UserLogged_1 | select -First 5 |select -last 1
$message= $DataCollected_1.Message.Split(":")[1]
$Props_1 = @{'Time' = $DataCollected_1.TimeCreated
'User' = $UserLogged_1
'Message' = $message }
$Obj_1 = New-Object -TypeName PSObject -Property $Props_1
Write-Output $Obj_1
}
}
我试过这样
$command='az vm run-command invoke --command-id RunPowerShellScript --name '.$vm_name.' --resource-group '.$resource_group.' --scripts @C:/Users/Get-ULogged_In.ps1; Get-ULogged_In 4/8/2020 4/10/2020';
但它没有成功。有人可以帮我吗?