Found 463 Articles for PowerShell

How to add help in the PowerShell function?

Chirag Nagrekar
Updated on 02-Nov-2020 10:59:04

287 Views

When we write a program, people from a non-programming background often expect to get much possible help related to the program. When we write the function and we declare the parameters, people who are unaware of what kind of input the parameter need, generally search for the help first using the Get-Help command and then they find only the parameters but not the description of it. For example, function TestFunct{    param(       #16 Digit Application ID       [parameter(Mandatory=$true)]       [String]$AppID,       #Date in the Unix Format - 2020-10-31T17:12:10+0530       [String]$Date ... Read More

How to enable or disable local user on Windows OS using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:54:29

3K+ Views

To disable the local user on the windows OS using PowerShell, we can use the Disable-Localuser command provided by the local user name. In the below example, we are going to disable the local user called TestUser.Disable-LocalUser -Name TestUserIf we see the GUI, the user account is disabled.To enable the above user, we can use the Enable-LocalUser command.Enable-LocalUser -Name TestuserTo run the above command on the remote computer, we can use the Invoke-Command method. We need to make sure local user account exist on the remote computer.Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{    Enable-Localuser -Name TestUser }Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{ ... Read More

How to delete the local group from the windows system using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:51:41

489 Views

To delete the local group from the windows system using PowerShell, you need to use the RemoveLocalGroup command as shown below.Remove-LocalGroup -Name TestGroupIn the above example, the local group name TestGroup will be removed from the local system. To remove the local group from the remote systems, we can use Invoke-Command as shown in the below example.Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock {Remove-LocalGroup -Name TestGroup}Remove-Localgroup command is supported from the PowerShell version 5.1 onwards and this command is a part of Microsoft.PowerShell.LocalAccounts module. If you have the PS version 5.1 or the local accounts module not available then you can use the ... Read More

How to remove a member from the local group using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:49:53

5K+ Views

To remove a member from the local group using PowerShell, we can use the RemoveLocalGroupMember command. This command is available in the module Microsoft.PowerShell.LocalAccounts in and above PowerShell version 5.1.To use this command, we need to provide two parameter values. One is the -Group (Local Group Name) and the second is -Member (Name of the Member to remove). For example, Remove-LocalGroupMember -Group Administrators -Member TestUserThe above command will remove TestUser from the local group Administrators.To use the above command on the remote computer, we need to use Invoke-Command. For example, Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{    Remove-LocalGroupMember -Group "Administrators" -Member ... Read More

How to create a new local group using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:48:00

807 Views

To create a new local group on the local or the remote system using PowerShell, we can use the NewLocalGroup command. ExampleNew-LocalGroup -Name "TestGroup" -Description "Test Group"OutputName       Description ----       ----------- TestGroup Test GroupYou can verify it from the Computer Management GUI.To create the local group on the remote systems, you can use Invoke-Command. For example, Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{    New-LocalGroup -Name 'TestGroup' -Description 'New Test Group' }The above command will create a New Local group named ‘TestGroup’ on the remote systems, Test1-Win2k12, and Test1-Win2k16.New-LocalGroup command is available in the module Microsoft.PowerShell.LocalAccounts which is part ... Read More

How to add users and groups to the local groups on Windows System using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:45:18

3K+ Views

To add users to the local groups using PowerShell, we need to use the Add-LocalGroupMember command (Module − Microsoft.PowerShell.LocalAccounts).Add-LocalGroupMember -Group "Administrators" -Member "NewLocalUser", "labdomain\Alpha", "Labdomain\ITSecurity"The above command adds 2 users (NewLocalUser (Local) and Alpha (Domain)) and one Domain Security Group ITSecurity to the Local Administrators group.You can also use the other local group name instead of Administrators.To add the new users in the local group on the remote system(s) use the Invoke-Command method. For example, Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16{    Add-LocalGroupMember -Group "Administrators" -Member    "NewLocalUser", "labdomain\Alpha", "Labdomain\ITSecurity" }Please note − To run the above command, the remote server must use ... Read More

How to get the list of local groups using PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 10:43:50

12K+ Views

To get the local groups on the windows system using PowerShell, you can use the Get-LocalGroup (Module: Microsoft.PowerShell.LocalAccounts) command. This command will list down all the groups on the particular system.If we check the properties of this command, it supports Name, Description, ObjectClass (user or group), PrincipalSource (ComputerName – Local or Remote), SID (Security Identifier).We will select them, PS C:\> Get-LocalGroup | Select Name, Objectclass, Principalsource, sid Name                                              ObjectClass PrincipalSource    SID ----           ... Read More

How to get the local Administrators group members using PowerShell?

Chirag Nagrekar
Updated on 01-Nov-2023 14:03:11

41K+ Views

To get the local Administrators group members using PowerShell, you need to use the GetLocalGroupMember command. This command is available in PowerShell version 5.1 onwards and the module for it is Microsoft.PowerShell.LocalAccounts. This module is not available in the 32-bit PowerShell version but on a 64-bit system.In the below example, we need to retrieve the Local Administrators group members, ExampleGet-LocalGroupMember -Group "Administrators"OutputObjectClass    Name          PrincipalSource -----------    ----          --------------- User          LABDOMAIN\delta Group         LABDOMAIN\Domain Admins User          TEST1-WIN2K12\Administrator User       ... Read More

How does PowerShell Pipeline work – Part 2?

Chirag Nagrekar
Updated on 16-Oct-2020 09:49:39

102 Views

In part-1 we have seen the PowerShell pipeline functionality using the ValueFromPipeline property. There is another cmdlet property known as ValueFromPipelineByPropertyName, which is also useful to know the PowerShell pipeline functionality.Like part-1 command, we can get this property name using the same Get-Command but the filter parameter we will use for the property is ValueFromPipelineByPropertyName.The below example is for the Stop-Service cmdlet.(Get-Command Stop-Service).ParameterSets.parameters | where{$_.ValueFromPipelineByPropertyName -eq 'True'} | Select Name, ParameterTypeOutputName ParameterType ---- ------------- Name System.String[]This means you can use Name property to stop the service. So here we will use Get-Service and its Name property to retrieve services and ... Read More

How does PowerShell Pipeline work – Part 1?

Chirag Nagrekar
Updated on 16-Oct-2020 09:44:27

118 Views

PowerShell is made easier with the Pipeline structure. With the Pipeline structure, we can pass the input of the left side command output or string to the right side of the command as the input. For example, Get-Service | Out-File c:\services.txtIn the above example, we are passing Get-Service output as an object to the Out-File command which is the right side of the Pipeline as the Input. Before going into detail about how the Pipeline works, we need to understand that every command we write produces output and that output is already formatted by the PowerShell using Pipeline.For example, Get-Process ... Read More

Advertisements