hypercube
asked on
User Rights Assignment - Adding a Username using powershell
Using the Windows GUI, I would be doing this:
gpedit.msc
Computer Configuration / Windows Settings / Security Settings / Local Policies
Audit Policy
Each Policy: Enable Success and Failure
THEN:
User Rights Assignment
Manage Auditing and Security Log … add “[username]”
Now I want to automate doing this using powershell. I've found the script by Tony Pombo but it seems unwieldy for such a simple task and I've had lots of problems getting the commands to be recognized at all.
Suggestions?
gpedit.msc
Computer Configuration / Windows Settings / Security Settings / Local Policies
Audit Policy
Each Policy: Enable Success and Failure
THEN:
User Rights Assignment
Manage Auditing and Security Log … add “[username]”
Now I want to automate doing this using powershell. I've found the script by Tony Pombo but it seems unwieldy for such a simple task and I've had lots of problems getting the commands to be recognized at all.
Suggestions?
ASKER
Subsun: Thanks! How would you change that approach for workstations on a peer-to-peer network? No "group of computers" possibility that I know of.
It would be great to do as you suggest and run these commands all from my own workstation!
If need be, I can run them on the target workstation as I have access to them all.
It would be great to do as you suggest and run these commands all from my own workstation!
If need be, I can run them on the target workstation as I have access to them all.
For computers In workgroup, to add local users, we don't have to specify the domain part.
Grant-UserRight -Computer ComputerA -Account UserA -Right SeSecurityPrivilege
I don't have any workgroup computer to test it, but I am pretty sure that it should work. I will test this as soon as I get a chance and let you know result.
gpedit.mscBTB, for enable auditing, you can use auditpol, Example.
Computer Configuration / Windows Settings / Security Settings / Local Policies
Audit Policy
Each Policy: Enable Success and Failure
auditpol /set /category:"System","Account Management","Account Logon","Logon/Logoff","Policy Change" /failure:enable /success:enable
Since the computers are not in domain, you probably have to use different credentials for each computer. If all the computer have same credential (Example, if all computers have same password for their administrator account), then it'll be easy to create a script which you can run from a work station.
ASKER
Subsun: Yes that works! Thank you!
The only nit remaining is that the "username" shows up in the settings as an indecipherable *S-1-5-21-2973359201 .........
I hate to think of living with that because how might one check the rights vs. usernames later on then?
Maybe there's a way to read and translate? That would be better than nothing.
The only nit remaining is that the "username" shows up in the settings as an indecipherable *S-1-5-21-2973359201 .........
I hate to think of living with that because how might one check the rights vs. usernames later on then?
Maybe there's a way to read and translate? That would be better than nothing.
ASKER
re: auditpol
I have a script for that already .. sorry I didn't mention it.
But so far, it has to run on the target workstation.
Now, if it could be run on my workstation and target various others (as for UserRights) then that would be great!
I have a script for that already .. sorry I didn't mention it.
But so far, it has to run on the target workstation.
Now, if it could be run on my workstation and target various others (as for UserRights) then that would be great!
What if you use ComputerA\UserA instead of UserA
Grant-UserRight -Computer ComputerA -Account ComputerA\UserA -Right SeSecurityPrivilege
Does this shows the correct user name instead of SID (S-1-5-21-2973359201)
ASKER
Grant-UserRight -Computer WIN10PRO3500 -Account WIN10PRO3500\Computerguy -Right SecurityPr
ivilege
Exception calling "AddPrivilege" with "2" argument(s): "Some or all identity references could not be translated."
At C:\Users\Public\Scripts\Us erRights.p s1:523 char:17
+ $lsa.AddPrivilege($Acct,$P riv)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IdentityNotMappedException
ivilege
Exception calling "AddPrivilege" with "2" argument(s): "Some or all identity references could not be translated."
At C:\Users\Public\Scripts\Us
+ $lsa.AddPrivilege($Acct,$P
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IdentityNotMappedException
I didn't get a chance to test this. I will update as soon as I can..
ASKER
thanks!!
OK.. As per my testing in order to add the local user the command has to run locally..
What is the operating system on your computers? is it windows 8 or 10?
What is the operating system on your computers? is it windows 8 or 10?
ASKER
All are Windows 10 Pro.
I guess you will have remote Powershell enabled. Can you test command
Invoke-Command -ComputerName <RemotecompterNamehere> -ScriptBlock {Ipconfig} -Credential (Get-Credential)
Command will prompt to enter credentials, enter remote computer credentials.
ASKER
Very interesting!
So it might look like this:
Invoke-Command -ComputerName 192.168.1.33 -ScriptBlock {Grant-UserRight -Computer ComputerA -Account UserA -Right SeSecurityPrivilege} -Credential (Get-Credential)
I'm getting an error:
[192.168.1.33] Connecting to remote server 192.168.1.33 failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooti ng Help topic.
+ CategoryInfo : OpenError: (192.168.1.33:String) [], PSRemotingTransportExcepti on
+ FullyQualifiedErrorId : ServerNotTrusted,PSSession StateBroke n
Maybe the amount of preparation on the target machines is greater than just running the commands locally???
So it might look like this:
Invoke-Command -ComputerName 192.168.1.33 -ScriptBlock {Grant-UserRight -Computer ComputerA -Account UserA -Right SeSecurityPrivilege} -Credential (Get-Credential)
I'm getting an error:
[192.168.1.33] Connecting to remote server 192.168.1.33 failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooti
+ CategoryInfo : OpenError: (192.168.1.33:String) [], PSRemotingTransportExcepti
+ FullyQualifiedErrorId : ServerNotTrusted,PSSession
Maybe the amount of preparation on the target machines is greater than just running the commands locally???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Any reason for computers are not added to domain?... like there is no server OS machine..
I know this is a stretch for peer-to-peer but it's been working well for us for some time.
Some of the issues we're dealing with here (i.e. the script) is not only to make the setup more efficient but to make repeated setups more efficient because recent MS Windows 10 updates have been erasing our firewall settings (amongst a one or two other things). So I'm trying to roll it all up into one script.
Had you not enticed me into the remote idea I'd have been done by now! :-)
Putting the module in a share is a great idea in moving forward! The idea was bouncing around in the back of my head but hadn't been fully formed.
I really appreciate the excellent suggestions and help!
The last hurdle is DCOM settings in a separate question:
https://www.experts-exchange.com/questions/28973373/DCOMCNFG-Settings-with-Powershell.html
I've not worked on any of the suggestions yet much.
ASKER
Really excellent help!!
I can see few experts has responded to DECOM question, is it not working?
ASKER
DCOM
I've not worked on any of the suggestions yet much.
I had an old script which I was using for similar requirement. I have made it in to following function, which should work locally, try and let me know if you get any error..
Add-DCOMPermission -User UserName
Function Add-DCOMPermission {
PARAM([string]$User)
function get-sid {
PARAM ($DSIdentity)
$ID = new-object System.Security.Principal.NTAccount($DSIdentity)
return $ID.Translate( [System.Security.Principal.SecurityIdentifier] ).toString()
}
$sid = get-sid $User
#DefaultLaunchPermission - Local Launch, Remote Launch, Local Activation, Remote Activation
$DCOMSDDLDefaultLaunchPermission = "A;;CCDCLCSWRP;;;$sid"
#DefaultAccessPermision - Local Access, Remote Access
$DCOMSDDLDefaultAccessPermision = "A;;CCDCLC;;;$sid"
#PartialMatch
$DCOMSDDLPartialMatch = "A;;\w+;;;$sid"
# Get the respective binary values of the DCOM registry entries
$Reg = [WMIClass]"\\$($env:COMPUTERNAME)\root\default:StdRegProv"
$DCOMDefaultLaunchPermission = $Reg.GetBinaryValue(2147483650,"software\microsoft\ole","DefaultLaunchPermission").uValue
$DCOMDefaultAccessPermission = $Reg.GetBinaryValue(2147483650,"software\microsoft\ole","DefaultAccessPermission").uValue
# Convert the current permissions to SDDL
$converter = new-object system.management.ManagementClass Win32_SecurityDescriptorHelper
$CurrentDCOMSDDLDefaultLaunchPermission = $converter.BinarySDToSDDL($DCOMDefaultLaunchPermission)
$CurrentDCOMSDDLDefaultAccessPermission = $converter.BinarySDToSDDL($DCOMDefaultAccessPermission)
# Build the new permissions
if (($CurrentDCOMSDDLDefaultLaunchPermission.SDDL -match $DCOMSDDLPartialMatch) -and ($CurrentDCOMSDDLDefaultLaunchPermission.SDDL -notmatch $DCOMSDDLDefaultLaunchPermission))
{
$NewDCOMSDDLDefaultLaunchPermission = $CurrentDCOMSDDLDefaultLaunchPermission.SDDL -replace $DCOMSDDLPartialMatch, $DCOMSDDLDefaultLaunchPermission
}
else
{
$NewDCOMSDDLDefaultLaunchPermission = $CurrentDCOMSDDLDefaultLaunchPermission.SDDL + "(" + $DCOMSDDLDefaultLaunchPermission + ")"
}
if (($CurrentDCOMSDDLDefaultAccessPermission.SDDL -match $DCOMSDDLPartialMatch) -and ($CurrentDCOMSDDLDefaultAccessPermission.SDDL -notmatch $DCOMSDDLDefaultAccessPermision))
{
$NewDCOMSDDLDefaultAccessPermission = $CurrentDCOMSDDLDefaultAccessPermission.SDDL -replace $DCOMSDDLPartialMatch, $DCOMSDDLDefaultAccessPermision
}
else
{
$NewDCOMSDDLDefaultAccessPermission = $CurrentDCOMSDDLDefaultAccessPermission.SDDL + "(" + $DCOMSDDLDefaultAccessPermision + ")"
}
# Convert SDDL back to Binary
$DCOMbinarySDDefaultLaunchPermission = $converter.SDDLToBinarySD($NewDCOMSDDLDefaultLaunchPermission)
$DCOMconvertedPermissionDefaultLaunchPermission = ,$DCOMbinarySDDefaultLaunchPermission.BinarySD
$DCOMbinarySDDefaultAccessPermission = $converter.SDDLToBinarySD($NewDCOMSDDLDefaultAccessPermission)
$DCOMconvertedPermissionsDefaultAccessPermission = ,$DCOMbinarySDDefaultAccessPermission.BinarySD
# Apply the changes
if ($CurrentDCOMSDDLDefaultLaunchPermission.SDDL -match $DCOMSDDLDefaultLaunchPermission)
{
write-host "DefaultLaunchPermission already set for $user"
}
else
{
$result = $Reg.SetBinaryValue(2147483650,"software\microsoft\ole","DefaultLaunchPermission", $DCOMbinarySDDefaultLaunchPermission.binarySD)
if($result.ReturnValue='0'){write-host "Applied DefaultLaunchPermission for $User"}
}
if ($CurrentDCOMSDDLDefaultAccessPermission.SDDL -match $DCOMSDDLDefaultAccessPermision)
{
write-host "DefaultAccessPermission already set for $user"
}
else
{
$result = $Reg.SetBinaryValue(2147483650,"software\microsoft\ole","DefaultAccessPermission", $DCOMbinarySDDefaultAccessPermission.binarySD)
if($result.ReturnValue='0'){write-host "Applied DefaultAccessPermission for $user"}
}
}
ASKER
It appears that this one works!! Thank youi!
You are welcome!
ASKER
Thank you!
Regarding the PowerShell option :
Using the Tony's module is pretty simple..
You need to download the module it a folder (In our example module is placed in C:\temp)
After that open PowerShell console using Run As Administrator Option. Sun the following commands to assign the privileges for user.
Open in new window
Let me know if you get any error.