この記事では SQL Server Agent の実行ユーザーを PowerShell で設定してみます。
Script
SQL Server Agent の WMI オブジェクトを取得して Change で実行ユーザーを設定します。
$svc = "*SQLAgent*"
$user = "testuser"
$pass = "testpass"
#Win32_ServiceのChangeメソッドの全パラメータ
$displayName = $null
$pathName = $null
$serviceType = $null
$errorControl = $null
$startMode = $null
$desktopInteract = $null
$startName = $user
$startPassword = $pass
$loadOrderGroup = $null
$loadOrderGroupDependencies = $null
$serviceDependencies = $null
$wmi = Get-WMIObject win32_service | Where-Object { $_.Name -like $svc }
$wmi.Change($displayName, $pathName, $serviceType, $errorControl, $startMode, $desktopInteract, $startName, $startPassword, $loadOrderGroup, $loadOrderGroupDependencies, $serviceDependencies)
捕捉
Changeのパラメータ
Change method of the Win32_Service class (Mbnapi.h) - Win32 apps
Modifies a Win32\_Service.
uint32 Change(
[in] string DisplayName,
[in] string PathName,
[in] uint32 ServiceType,
[in] uint32 ErrorControl,
[in] string StartMode,
[in] boolean DesktopInteract,
[in] string StartName,
[in] string StartPassword,
[in] string LoadOrderGroup,
[in] string LoadOrderGroupDependencies[],
[in] string ServiceDependencies[]
);