Summary
- How to check if DOMAIN_NAME/USER_NAME has Administrator privileges?
- How to Import-Module Microsoft.Powershell.LocalAccounts?
I'm using the build-in LoginInformationDlg with DOMAIN_NAME and USER_NAME properties for specifying the credentials of the windows service, which I want to install.
The service must have administrator privileges. Therefore I want to check whether the user is part of the admin group.
I want to check this with Get-LocalGroupMember
Code: Select all
$admins_sid = [System.Security.Principal.SecurityIdentifier]::new("S-1-5-32-544")
$administrators = Get-LocalGroupMember -SID $admins_sid | Select-Object -ExpandProperty name
$userHasAdministratorPrivileges = $administrators -icontains $domainUser
The reason is that the Microsoft.Powershell.LocalAccounts module is not loaded.The term 'Get-LocalGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program
Therefore I want to import the module with
Code: Select all
Import-Module Microsoft.Powershell.LocalAccountsYou can reproduce it with an PowerShell inline Script
Code: Select all
#Requires -version 3
Param()
# Let's see which Powershell we're using. Feel free to remove this function
Function Say-Hello() {
Get-Module
Import-Module Microsoft.Powershell.LocalAccounts
Get-Module
}
# Your code goes here
Say-Hello
When i execute Get-Module from a PowerShell command prompt the LocalAccounts module is available. The problem is that it is not available when I run it from within Advanced Installer or the MSI setup.
Do you have any hints?
best regards,
Stefan
FOLLOW US
Get the latest news in Application Packaging