Find Number with Thousand Separator in Python

Arnab Chakraborty
Updated on 17-May-2021 12:51:49

528 Views

Suppose we have a number n, we have to return this number into string format where thousands are separated by comma (", ").So, if the input is like n = 512462687, then the output will be "512, 462, 687"To solve this, we will follow these steps −res := n as stringres := reversed form of resans := a blank stringfor i in range 0 to size of res - 1, doif i mod 3 is same as 0 and i is not same as 0, thenans := ans concatenate ', 'ans := ans concatenate res[i]ans := reversed form of ansreturn ... Read More

Set Local User Account Settings Using PowerShell

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

3K+ 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 }

Find Locked Local User Accounts Using PowerShell

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

2K+ 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}

Validate Path with PowerShell Function Parameter

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

2K+ 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

Copy Files of Specific Extension Using PowerShell

Chirag Nagrekar
Updated on 17-May-2021 12:38:39

1K+ Views

To copy the files using the specific files extension using PowerShell, we can use the Copy-Item command.The below command will copy only the .ps1 files from the source to the destination.For example, PS C:\> Copy-Item -Path C:\Temp -Recurse -Filter *.ps1 -Destination C:\Temp1\ -VerboseIf the C:\Temp1 doesn't exist, it will create the destination folder and then copy the content of the file but the problem with this command is it copies the subfolders as well which doesn’t have the .ps1 file.So to copy the with the same folder structure without empty directories and the specific file extension we can write the ... Read More

Get Disabled Local User Accounts Using PowerShell

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

2K+ Views

To get the disabled local user accounts using PowerShell on the local and the remote system, we can use the WMI or the CIM instance method with the Win32_UserAccount class and the Disabled property to filter the result.PS C:\> gwmi win32_useraccount | where{$_.Disabled -eq $true}You can filter out the properties using the specific properties use the Select-Object pipeline command.PS C:\> gwmi win32_useraccount | where{$_.Disabled -eq $true} | Select Name, FullName, CaptionYou can also use the CIM instance method alternatively, PS C:\> Get-CimInstance win32_useraccount | where{$_.Disabled -eq $true}To get the disabled accounts on the remote systems, use the -ComputerName parameter in ... Read More

Find a Good String from a Given String in Python

Arnab Chakraborty
Updated on 17-May-2021 12:30:33

1K+ Views

Suppose we have a string s with lower and upper case English letters. We shall consider a string is a good string which does not have any two adjacent characters s[i] and s[i + 1] where −0

Find Kth Missing Positive Number in an Array using Python

Arnab Chakraborty
Updated on 17-May-2021 12:30:13

628 Views

Suppose we have an array called nums with positive sorted strictly increasing values, and also have an integer k. We have to find the kth positive integer that is missing from this array.So, if the input is like nums = [1, 2, 4, 8, 12], k = 6, then the output will be 10 because the missing numbers are [3, 5, 6, 7, 9, 10, 11], here the 6th term is 10.To solve this, we will follow these steps −nums := a new set from the elements present in numscount := 0num := 1while count < k, doif num is ... Read More

Find Number of Good Triplets in Python

Arnab Chakraborty
Updated on 17-May-2021 12:29:49

2K+ Views

Suppose we have an array nums, and three different integers a, b and c. We have to find the number of good triplets. A triplet (nums[i], nums[j], nums[k]) is said to be a good triplet if the following conditions are true −0

Check for Three Consecutive Odds in Python

Arnab Chakraborty
Updated on 17-May-2021 12:29:21

658 Views

Suppose we have an array called nums, we have to check whether there are three consecutive odd numbers in nums or not.So, if the input is like nums = [18, 15, 2, 19, 3, 11, 17, 25, 20], then the output will be True as there are three consecutive odds [3, 11, 17].To solve this, we will follow these steps −length:= size of numsif length is same as 1 or length is same as 2, thenreturn Falseotherwise, for i in range 0 to size of nums - 3, doif nums[i], nums[i+1] and nums[i+2] all are odds, thenreturn Truereturn FalseExample (Python)Let ... Read More

Advertisements