To convert the hashtable to the JSON format we can use the ConvertTo-Json command. First, we have the following hashtable,Example$Body = [PSCustomObject]@{ AppName = 'StorageXIO' AppID ='xo2ss-12233-2nn12' License = 'valid' }To convert the hashtable to the JSON format,$Body | ConvertTo-JsonOnce you run the above command, properties are converted to the JSON format.Output{ "AppName": "StorageXIO", "AppID": "xo2ss-12233-2nn12", "License": "valid" }
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
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
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
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
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
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
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
We are given with a string of characters and the task is to calculate the count of pairs having both the elements as vowels. As we know there are five vowels in English alphabet i.e. a, i, e, o, u and other characters are known as Consonants.Input − string str = "tutorials point”Output − Count the pairs of vowels in the given string are: 2Explanation − From the given string we can form pairs as (t, u), (u, t), (t, o), (o, r), (r, i), (i, a), (a, l), (l, s), (s, p), (p, o), (o, i), (i, n) and ... Read More
We are given with an array of positive integer numbers and an integer variable k. The task is to calculate the count of the number of elements in an array which is divisible by the given value k.Input − int arr[] = {4, 2, 6, 1, 3, 8, 10, 9}, k = 2Output − Count the number of elements in an array which are divisible by 2 are − 5Explanation − we will divide the elements in an array by a value k and check whether the reminder is 0 or not. So, 4 is divisible by 2, 2 is ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP