• 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-6605e506d3435356253305/] 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-6605e506d3c6d301259531/] [crayon-6605e506d3c73910351179/] 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-6605e506d3e0c392817869/] [crayon-6605e506d3e10086724391/] 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-6605e506d4158944870804/] [crayon-6605e506d415b697796457/] 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-6605e506d4283160166111/] [crayon-6605e506d4286965289431/] 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-6605e506d437d518290684/] [crayon-6605e506d4380600313169/] 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-6605e506d45e5806173896/] [crayon-6605e506d45e9779367438/] 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 […]