使用 Intune 我相信問題是我無法從 SYSTEM 帳戶訪問網路共享,所以真的問,作為 INTUNE 中的修復腳本,是否有任何方法可以以 SYSTEM 身份運行腳本,但通過腳本塊呼叫命令作為另一個用戶(具有網路共享權限
我需要將檔案從網路共享復制到 C:\windows\temp 檔案夾,然后使用 Microsoft Intune 中的主動修復腳本在本地計算機上安裝該軟體
$FSPath = "C:\Program Files (x86)\Freshdesk\Freshservice Discovery Agent"
$serviceName = 'FSDiscoveryAgent'
$tempPath = "c:\windows\temp"
$FSService = Get-Service -Name $serviceName
if(Test-Path $FSPath -eq $false){
Write-Output "Freshservice agent not installed on workstation."
$password = ConvertTo-SecureString "hello1" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("myUsername",
$password)
$alternateUsers = [scriptblock]{
Copy-Item -Path (Join-Path -Path "\\myShare.com\util\software\FreshService\2.9 Agent" -ChildPath "fs-windows-agent-2.9.0.msi") `
-Destination "$tempPath\fs-windows-agent-2.9.0.msi"
}
Invoke-Command -ScriptBlock $alternateUsers -Credential $Cred
}else{
Write-Output "Freshservice agent is installed"
}
uj5u.com熱心網友回復:
我建議為此使用常規 Intune Win32 應用程式部署功能,而不是濫用此任務的主動修復。在腳本中存盤憑據被認為是不好的做法,內容將以純文本形式記錄在 Intune 管理擴展日志中。Win 32 應用程式提供檢測規則,您可以測驗該服務是否存在于設備上 - 如果未安裝代理,否則將其視為已安裝或添加額外的邏輯來檢查特定版本。 https://docs.microsoft.com/en-us/mem/intune/apps/apps-win32-add , https://github.com/Microsoft/Microsoft-Win32-Content-Prep-Tool/releases/latest
uj5u.com熱心網友回復:
這是允許我在安裝軟體時使用另一個帳戶的作業代碼。明天我會嘗試 intune
$password = ConvertTo-SecureString "p@ssw0rd" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("domain.com\adminAccount", $password)
$alternateUsers = [scriptblock]{
Copy-Item -Path (Join-Path -Path "\\sharedDrive.com\util\software\FreshService\2.9 Agent" -ChildPath "fs-windows-agent-2.9.0.msi") -Destination "C:\windows\temp\fs-windows-agent-2.9.0.msi"
}
# https://www.itdroplets.com/run-a-command-as-a-different-user-in-powershell/
$GetProcessJob = Start-Job -ScriptBlock $alternateUsers -Credential $Cred
Wait-Job $GetProcessJob
$GetProcessResult = Receive-Job -Job $GetProcessJob
Write-Output $GetProcessResult
if($GetProcessResult.state -eq "Completed"){
Start-Process "C:\windows\temp\fs-windows-agent-2.9.0.msi" -ArgumentList "/i /qn"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/402177.html
下一篇:在空格之間選擇子字串
