To create a new local user in the Windows operating system using PowerShell, we can use the New-LocalUser cmdlet. The below command will create the TestUser with no password.New-LocalUser -Name TestUser -NoPasswordOutputName Enabled Description ---- ------- ----------- TestUser TrueTestUser account has been enabled here. To provide the password for the user, the password should be in the secure string format. We can pass the password as shown below.$pass = "Admin@123" | ConvertTo-SecureString -AsPlainText -Force New-LocalUser -Name TestUser -Password $passThe above commands will create the TestUser with the password. To add the password and account-related settings we can directly provide parameters ... Read More
Let say we have one MSI file and we need to install the MSI file on the remote computers using PowerShell but that MSI file should be deployed with the Batch file and should be executed using PowerShell.In this example, we have a 7-zip MSI file and batch file we will first write the installation instructions as shown below.msiexec /i "C:\temp\7z1900-x64.msi" /quietWe have the installation MSI package located at the C:\temp location. We will save the above instruction inside the 7ZipInstaller.bat file.Now we need to call the batch file as shown below. −Wait will wait for the batch file to ... Read More
Suppoe we have an array with distinct elements called salary where salary[i] is the salary of ith employee. We have to find the average salary of employees excluding the minimum and maximum salary.So, if the input is like salary = [8000, 6000, 2000, 8500, 2500, 4000], then the output will be 5125.0, as the minimum and maximum salary values are 2000 and 8500, so excluding them the average salary values are [8000, 6000, 2500, 4000] so the average is (8000 + 6000 + 2500 + 4000)/4 = 5125.To solve this, we will follow these steps −delete minimum of salary from ... Read More
Suppose we have an integer n and another integer start. We have to create an array called nums where nums[i] = start + 2*i (i start from 0) and n is the size of nums. Then find the bitwise XOR of all elements of nums.So, if the input is like n = 6, start = 2, then the output will be 14 because the array will be like [2+2*0, 2+2*1, ... 2+2*5] = [2, 4, 6, 8, 10, 12], then XOR of each element present in the array is 14.To solve this, we will follow these steps −count := startwhile ... Read More
Suppose we have an array nums. The running sum of an array as rs[i] is sum of all elements from nums[0] to nums[i]. Finally return the entire running sum of nums.So, if the input is like nums = [8, 3, 6, 2, 1, 4, 5], then the output will be [8, 11, 17, 19, 20, 24, 29], becausers[0] = nums[0] rs[1] = sum of nums[0..1] = 8 + 3 = 11 rs[2] = sum of nums[0..2] = 8 + 3 + 6 = 17 and so onTo solve this, we will follow these steps −n:= size of numsrs:= [nums[0]]for i ... Read More
Suppose we have an array called prices where prices[i] represents price of the ith item in a shop. There is a special offer going on, if we buy the ith item, then we will get a discount equivalent to prices[j] where j is the minimum index such that j > i and price of jth item is less or same as price of ith item (i.e. prices[j] = prices[j], thenprices[i] := prices[i] - prices[j]come out from the loopotherwise, j := j + 1return pricesExample (Python)Let us see the following implementation to get better understanding − Live Demodef solve(prices): for i ... Read More
Suppose we are given a linked list that has the start node as "head", and two integer numbers m and n. We have to traverse the list and delete some nodes such as the first m nodes are kept in the list and the next n nodes after the first m nodes are deleted. We perform this until we encounter the end of the linked list. We start from the head node, and the modified linked list is to be returned.The linked list structure is given to us as −Node value : next : So, if the ... Read More
Azure VM RAM and CPU size depend on the hardware profile chosen for the VM. In this example, we will retrieve VM (TestMachine2k16) hardware profile and then we can find how much RAM or CPU is allocated to it.To get the Size of the Azure VM, PS C:\> $azvm = Get-AzVM -VMName 'TestMachine2k16' PS C:\> $azvm.HardwareProfile.VmSizeOutputStandard_DS2_v2You can check the above size on the Microsoft Azure website to know how much RAM and CPU are associated with it and another way using the PowerShell by using the Get-AZVmSize command.PS C:\> $vmsize = $azvm.HardwareProfile.VmSize PS C:\> Get-AzVMSize -VMName $azvm.Name -ResourceGroupName $azvm.ResourceGroupName | ... Read More
Once you are connected to the Azure Account, there are possibilities that the Get-AzVM will display the VMs from all the Azure Subscriptions.To find the specific Azure VM Subscription name, we will first retrieve the details of the VM using the Get-AzVM and it has an ID property that contains the Subscription ID and from the subscription ID property, we can retrieve the name of the Azure Subscription Name.PS C:\> $azvm = Get-AzVM -Name TestMachine2k16 PS C:\> $subid = ($azvm.Id -split '/')[2] PS C:\> (Get-AzSubscription -SubscriptionId $subid).NameThe above will retrieve the name of the subscription.
To retrieve the azure VM resource group using PowerShell, we first need to retrieve the Azure VM details using Get-AZVm and then we can use its property called ResourceGroup.Before getting the details of the Azure VM, make sure that you are connected to the Azure Account using the Connect-AzAccount command.In this example, we are going to retrieve the Azure VM named TestMachine2k16 to retrieve the VM details.$azvm = Get-AzVM -Name TestMachine2k16To get the resource group name, use its property ResourceGroupName.PS C:\> $azvm.ResourceGroupName ANSIBLETESTRG
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP