0

我在我们的 Windows 机器上有一个 powershell 脚本,它查看一个配置文件 (.ini) 来查找特定的文本,如果该文本不存在,它将自动添加它。可悲的是,我无法找到使用 shell 脚本(.sh)在终端中执行此操作的方法

幸运的是,我们刚刚通过 Intune 将 PowerShell 7 部署到我们的 macOS 设备上,我希望能够创建一个在 Windows POSH 脚本中使用相同信息的 .sh。

我知道 $path 变量需要更新到它在 macOS 上的位置。已替换实际的证书信息。

Windows PowerShell 脚本

#Variables
$path = "C:\Program Files\BMC Software\Client Management\Client\config\mtxagent.ini"

# Mark file as writable
ATTRIB -r $path

#Certificate Authority fix
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertAuth=', 'CertAuth=<text>' | Set-Content -Path $path
#If config file already has correct value, this fixes the previous command to add it
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertTrusted=', 'CertTrusted=<text>' | Set-Content -Path $path

#Certificate Trusted fix
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertAuth=<text><text>', 'CertAuth=<text>' | Set-Content -Path $path
#If config file already has correct value, this fixes the previous command to add it
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertTrusted=<text><text>', 'CertTrusted=<text>' | Set-Content -Path $path

# Mark file as read-only
ATTRIB +R $path

如何通过 Intune 从 .sh 中执行此操作?

#!/bin/sh 
pwsh
#Variables
$path = "/usr/local/bmc-software/client-management/client/etc/mtxagent.ini"

#Certificate Authority fix
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertAuth=', 'CertAuth=<text>' | Set-Content -Path $path
#If config file already has correct value, this fixes the previous command to add it
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertTrusted=', 'CertTrusted=<text>' | Set-Content -Path $path

#Certificate Trusted fix
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertAuth=<text><text>', 'CertAuth=<text>' | Set-Content -Path $path
#If config file already has correct value, this fixes the previous command to add it
$text = (Get-Content -Path $path -ReadCount 0) -join "`n"
$text -replace 'CertTrusted=<text><text>', 'CertTrusted=<text>' | Set-Content -Path $path
4

0 回答 0