Found 989 Articles for Software & Coding

How to get the disk information using PowerShell?

Chirag Nagrekar
Updated on 25-Jan-2021 07:15:06

6K+ Views

To get the Windows disk information using PowerShell, we can use the WMI command or the CIM class command.With the WMI command, Gwmi Win32_LogicalDiskWith the CIM instance method, Get−CimInstance Win32_LogicalDisk You can see both the outputs are identical. Let’s use one of them.DeviceID DriveType ProviderName VolumeName Size FreeSpace -------- --------- ------------ ---------- ---- --------- C: 3 53317988352 44027125760 D: 5 HRM_SSS_X64FREE_EN-US_DV5 3694962688 0 E: 3 Temporary Storage 10734268416 10238513152Now there are different drive types associated with Windows and they each have an identical number. For example, Drive Type ‘3’ mentions the logical disk. The other types are as below.2 = ... Read More

How to install the Nuget Package using PowerShell?

Chirag Nagrekar
Updated on 25-Jan-2021 07:18:40

19K+ Views

Nuget is the package management tool for the .NET and it is similar to PowerShellGet, MSI packages which support several commands and packages to work with PowerShell.NuGet supports Install−Package, Update−Package, Find-Package, and Get−Package command and if Nuget package is not installed in your system, you may not find a package or install any package.For more reference about Nuget, check the websites below.https://www.nuget.orghttps://docs.microsoft.com/en-us/nuget/reference/powershell−referenceTo install NuGet, we need to use the Install−PackageProvider command. Use the below command to install the Nuget package.Install−PackageProvider −Name Nuget −ForceOn some machines, you will get the error message regarding downloading the package from the internet. If you ... Read More

Ways to use Where-Object in PowerShell

Chirag Nagrekar
Updated on 25-Jan-2021 07:11:07

2K+ Views

Where−Object or (alias: Where) in PowerShell is used to filter the data output provided through the Pipeline.There are two methods we can use the Where−Object for the pipeline inputs.a. ScriptMethod −In this method, we use ScriptBlock to filter the output with the Property name, value, and the comparison operator.Get−Service | Where−Object{($_.StartType −eq 'Automatic') −and ($_.Status −eq 'Stopped')}You can also use Alias: Where instead of Where−Object.Get−Service | Where{($_.StartType −eq 'Automatic') −and ($_.Status −eq 'Stopped')} Other Syntax ‘?’ (Question Mark) can also be used Instead of the Where−Object command.Get−Service | ?{($_.StartType −eq 'Automatic') −and ($_.Status −eq 'Stopped')}The above commands will get the ... Read More

How to change the color of the PowerShell ISE editor using command?

Chirag Nagrekar
Updated on 18-Jan-2021 07:44:08

2K+ Views

To change the color of the ISE Editor, we need to use $psISE cmdlet which is only available for the ISE editor.Now in the ISE editor, we have many colors some are visible (ScriptPane color, Console Color, etc) and some appear while executing a script (Error, Warning, Verbose). These properties are as below.ErrorForegroundColor : #FFFF9494 ErrorBackgroundColor : #00FFFFFF WarningForegroundColor : #FFFF8C00 WarningBackgroundColor : #00FFFFFF ... Read More

How to change PowerShell ISE font Size using command?

Chirag Nagrekar
Updated on 18-Jan-2021 07:41:03

2K+ Views

To change the font size of the PowerShell ISE editor using the command, we need to use the cmdlet $PSISE which is only loaded inside the PowerShell ISE console. You won’t find it in the main PowerShell console.Once you run this command, there are various properties available. For example, PS C:\> $psISE CurrentPowerShellTab          : Microsoft.PowerShell.Host.ISE.PowerShellTab CurrentFile                   :  Microsoft.PowerShell.Host.ISE.ISEFile CurrentVisibleHorizontalTool  : CurrentVisibleVerticalTool    : Options : Microsoft.PowerShell.Host.ISE.ISEOptions PowerShellTabs                :  {PowerShell 1}You need to select the Options Property and then need to ... Read More

How to traceroute using PowerShell?

Chirag Nagrekar
Updated on 18-Jan-2021 07:38:30

14K+ Views

Traceroute is the way to determine the hopes that the packets are passing through when requested. In the command prompt, that utility is called the tracert and we can also use that utility to trace the network packets. For example, PS C:\> tracert google.com Tracing route to google.com [216.58.203.142] over a maximum of 30 hops: 1    1 ms    1 ms    1 ms 192.168.0.1 2    2 ms    2 ms    2 ms 45.114.51.246 3    8 ms    4 ms    4 ms 103.210.200.141 4    21 ms   *       * 10.10.125.29 5 ... Read More

How to format string using PowerShell?

Chirag Nagrekar
Updated on 18-Jan-2021 07:32:31

5K+ Views

To format a string in a PowerShell we can use various methods. First using the simple expanding string method.PS C:\> $str = 'PowerShell' PS C:\> Write-Output "Hello $str !!!!" Hello PowerShell !!!!Second, using the format method. In this method, we will use the Format function of the String .NET class.PS C:\> $str = "PowerShell" PS C:\> [String]::Format("Hello $str...!!!") Hello PowerShell...!!!The third method using the Format operator. We can use the number format here as shown below.PS C:\> $str = 'PowerShell' PS C:\> "Hello {0}" -f $str Hello PowerShellIf we have multiple variables then we need to increase the numbers inside ... Read More

How to check the website status code using PowerShell?

Chirag Nagrekar
Updated on 18-Jan-2021 07:31:12

9K+ Views

Website status code is meant to be the status of the website as if the website request from the client is successful or not if the website is available or any error on the webpage which is causing the handshake failed with the client.There are various website status codes. Please refer to the below link for them.https://en.wikipedia.org/wiki/List_of_HTTP_status_codesTo retrieve the status using PowerShell, we will first connect the webpage using the Invoke-WebRequest command and then we can use the property StatusCode. For example, $req = Invoke-WebRequest -uri "https://theautomationcode.com" $reqOutputStatusCode : 200 StatusDescription : OK Content :         ... Read More

How to download images using Invoke-Webrequest in PowerShell?

Chirag Nagrekar
Updated on 18-Jan-2021 07:26:10

3K+ Views

To download the images from the webpage using the Invoke-WebRequest command, we can use the images property from the result to retrieve the images URL, and later we can use the method to download them at the specific location. Consider we have the URI: https://theautomationcode.com to retrieve the images.Once you run the below command, you can see the Images property there.Invoke-WebRequest -Uri "https://theautomationcode.com/feed/"To retrieves the images URL, $req = Invoke-WebRequest -Uri "https://theautomationcode.com/feed/" $req.Images | Select -ExpandProperty srcOutputhttps://i1.wp.com/theautomationcode.com/wp-content/uploads/2020/11/image-9.png?resize=178%2C60&ssl=1 https://i0.wp.com/theautomationcode.com/wp-content/uploads/2020/11/image-10.png?resize=640%2C68&ssl=1All the above URLs point to the images, so we can download that.$wc = New-Object System.Net.WebClient $req = Invoke-WebRequest -Uri "https://theautomationcode.com/feed/" $images = ... Read More

How to use Array Splatting in PowerShell?

Chirag Nagrekar
Updated on 18-Jan-2021 07:23:45

525 Views

Splatting is the method to pass the collection of parameters as a single unit so it will be easier for the command to read. Array splatting uses the splat values which do not require parameter names. The values must be in positional number order in the array.We have a below copy example, in which we are copying one file from the source to the destination. Now we are not specifying the parameters here because we will use the positional parameter for the source path and the destination path.If we check the help for those parameters, we will come to know ... Read More

Advertisements