• PowerShell script to keep screen active
    30 May

    PowerShell Script to Keep Screen Active

    Using while Loop with SendKeys() Method Use the while loop to invoke the SendKeys() method for an unlimited time to keep the PC/Laptop screen active using PowerShell. [crayon-6768091c851d5913318468/] Here, we used the New-Object cmdlet to create an instance of the WSH (Windows Script Host) Shell object using COM (Component Object Model) technology and stored it […]

  • Run PowerShell script at Start up
    28 May

    Run PowerShell Script at Startup

    Our script will open the Windows Calculator application at Windows startup and login based on the solution you will choose from. To meet your requirements, you can replace the script in file.ps1 with your script. Using Startup Folder Use the Startup folder to run the PowerShell script at startup. To do this, we must follow […]

  • PowerShell get hostname from ip address
    28 May

    Get Hostname from IP Address in PowerShell

    Using Resolve-DnsName Cmdlet To retrieve the hostname from the given IP address in PowerShell, use the Resolve-DnsName cmdlet with -Type and PTR parameters. [crayon-6768091c855c3541351481/] [crayon-6768091c855c5087568041/] In this example, the Resolve-DnsName cmdlet resolves the IP addresses to DNS names (hostnames). The -Type parameter is used to specify that the query should be for a PTR record […]

  • PowerShell for loop from 1 to 10
    28 May

    PowerShell for Loop 1 to 10

    Using Traditional for Loop Use the traditional for loop to print from 1 to 10 on the PowerShell console. [crayon-6768091c8570d655591634/] [crayon-6768091c85710179174315/] In the above example, we used the traditional for loop to iterate from 1 to 10. The header of the for loop consists of three parts separated by a semicolon (;). The first part […]

  • PowerShell format number with commas
    28 May

    PowerShell Format Number with Commas

    Using -f Format Operator Use the format operator (-f) to format the given number with commas in PowerShell. [crayon-6768091c85a7b167937660/] [crayon-6768091c85a7f476188710/] First, the PowerShell variable is initialized with an 8 digit number. Then the -f format operator to format a number with commas as thousands separators. The format string "{0:N0}" specified that the number should be […]

  • PowerShell create shortcut on desktop
    28 May

    PowerShell Create Shortcut on Desktop

    Using New-Item Cmdlet To create a shortcut on Desktop using PowerShell: Use the GetFolderPath() method to define the shortcut’s path and name. Define the shortcut’s target path. Use the New-Item cmdlet to create a .lnk file of the target path. You must open PowerShell as an Administrator to run the following script. [crayon-6768091c85bad962819479/] [crayon-6768091c85bb0895612073/] First, […]

  • PowerShell Concatenate String and variable
    28 May

    Concatenate String and Variable in PowerShell

    Using Concatenation Operators Use concatenation operator represented by + to concatenate String and variable in PowerShell. [crayon-6768091c85cc2194523015/] [crayon-6768091c85cc6488135400/] The + is the most basic concatenation operator; we used it to concatenate the "Let's learn "string with the $variable and stored the new string in the $concatenatedStr variable, which we further used with Write-Host cmdlet to […]

  • PowerShell check if process is running
    28 May

    PowerShell Check If Process Is Running

    Using Get-Process Cmdlet Use the Get-Process cmdlet to check if process is running in PowerShell. With the Get-Process cmdlet, we can display the list of processes running on the system. [crayon-6768091c85f9f449491934/] [crayon-6768091c85fa3338030036/] We can observe the Get-Process cmdlet retrieved all the information of the process currently running on my system. From the above list, we […]

  • PowerShell check if port is open
    27 May

    PowerShell Check If Port Is Open

    The following commands are used to determine if the specified port is open on the remote computer, but we can also use them on the local computer. To use them on the local machine, we must replace the example.com with localhost. Note that the specified port in the below commands may or may not be […]