Found 463 Articles for PowerShell

How to find the locked local user accounts using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:48:43

1K+ Views

To get the locked user accounts on the local or the remote machines using PowerShell, we can use the wmi method.PS C:\> gwmi win32_useraccount | where{$_.Lockout -eq $true}You can also use the CIM instance method alternatively.PS C:\> Get-CimInstance Win32_Useraccount | where{$_.Lockout -eq $true}To get the locked local user accounts on the remote computer, you can use the -ComputerName parameter in the WMI class or the CIM instance. For example,PS C:\> gwmi win32_useraccount -ComputerName TestMachine1, TestMachine2 | where{$_.Lockout -eq $true}

How to set the local user account settings using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:51:03

2K+ Views

To set the local user account settings related to the account or the password expiration, we can use the Set-LocalUser command.The below command will change the local user Testuser account and password set to never expire.Set-LocalUser -Name Testuser -AccountNeverExpires -PasswordNeverExpires $true -VerboseThe below command will set the account expiry,Set-LocalUser -Name Testuser -AccountExpires 05/11/2022 -VerboseTo run the above commands on the remote computers, use the Invoke-Command.Invoke-Command -ComputerName Computer1, computer2 -ScriptBlock{ Set-LocalUser -Name Testuser -AccountNeverExpires -PasswordNeverExpires $true -Verbose } Invoke-Command -ComputerName Computer1, computer2 -ScriptBlock{ Set-LocalUser -Name Testuser -AccountExpires 05/11/2022 -Verbose }

How to change the local user account password using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 13:39:09

9K+ Views

To change the local user account password using PowerShell, we can use the Set-LocalUser command with the Password parameter. This password parameter should be in the secure string. So we need to ask the user to input the password as a secure string or need to explicitly convert the plain text password to the secure string. For example, $localuser = Read-Host "Enter Local UserName" $password = Read-Host "Enter local user account password " -AsSecureString Set-LocalUser -Name $localuser -Password $password -VerboseIf you need to set the password without asking the user prompt then you need to convert the plain text password ... Read More

How to add the user to the local Administrators group using PowerShell?

Chirag Nagrekar
Updated on 04-Nov-2023 01:25:40

29K+ Views

To add the AD user or the local user to the local Administrators group using PowerShell, we need to use the Add-LocalGroupMember command.To add the local user to the local Administrators group, Add-LocalGroupMember -Group Administrators -Member TestUser -VerboseThe above command will add TestUser to the local Administrators group. You can provide any local group name there and any local user name instead of TestUserYou can also add the Active Directory domain user to the Local Administrators group by providing the domain name if the computer is in the same domain.For example, we will add the Beta user from the AutomationLab ... Read More

How to create a new local user in windows using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:20:05

3K+ Views

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

How to validate the path with the PowerShell function parameter?

Chirag Nagrekar
Updated on 17-May-2021 12:42:17

1K+ Views

To validate the file or folder path inside the PowerShell function parameter, we need to use the ValidateScript command. Generally, we write the script as below to validate the path.function Validate-Path{    param(       [parameter(Mandatory)]       [String]$Path    )    if(Test-Path $Path) {Write-Output "Path is valid"}    else{Write-Output "Path is invalid"} }OutputPS C:\> Validate-Path -Path C:\Temp Path is validWe can add similar functionality inside the function parameter with the validatescript argument so the script will throw the error initially at the parameters check. See below, function Validate-Path{    param(       [parameter(Mandatory)]       ... Read More

How to install MSI file using batch file in PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:17:21

3K+ Views

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

How to retrieve the Azure VM RAM and CPU size using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:08:03

4K+ Views

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

How to retrieve the Azure VM Subscription Name using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:07:25

1K+ Views

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.

How to retrieve the Azure VM resource group using PowerShell?

Chirag Nagrekar
Updated on 17-May-2021 12:06:52

1K+ Views

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

Previous 1 ... 7 8 9 10 11 ... 47 Next
Advertisements