Found 463 Articles for PowerShell

How to use CSS style in PowerShell HTML Output?

Chirag Nagrekar
Updated on 11-Nov-2020 11:54:03

4K+ Views

Cascading Style Sheets (CSS) in general used for formatting HTML with styles. It describes how the HTML elements should be displayed.Once we get the output from the Convertto-HTML command, we can use the CSS style to make the output more stylish.Consider we have the below example for converting the services output table to the HTML.ExampleGet-Service | Select Name, DisplayName, Status, StartType | ConvertTo-Html -Title "Services" -PreContent "Services Output" | Out-File Servicesoutput.htmlThe output is simple for the above command in HTML.There are multiple ways to add the CSS style in the above HTML file so the file output becomes more stylish. ... Read More

Explain HTML formatting in PowerShell?

Chirag Nagrekar
Updated on 11-Nov-2020 11:43:02

2K+ Views

HTML is another form of output in PowerShell. It is the rich form of output and you can use various CSS styles to make the output more interactive. We will use the Convertto-HTML cmdlet to convert the output in the HTML format.Here is the Syntax of the Convertto-HTML cmdlet.ExampleConvertTo-Html     [-InputObject ]     [[-Property] ]     [[-Body] ]     [[-Head] ]     [[-Title] ]     [-As ]     [-CssUri ]     [-PostContent ]     [-PreContent ]     [-Meta ]     [-Charset ]     [-Transitional]     [] ... Read More

How to use a transcript in PowerShell?

Chirag Nagrekar
Updated on 11-Nov-2020 11:36:12

1K+ Views

Transcript in Powershell is like a recording session. So whenever you start a transcript in PowerShell, it starts recording your commands and outputs and doesn't matter if there is any error output, it gets recorded too. To start the transcript, you need to run Start-Transcript command at the beginning, and then whatever you write, it will get recorded.To start the recording, you need to write Start-Transcript command and have to give the path for the transcript as shown in the below example, ExampleStart-Transcript -Path C:\Temp\sessionrecord.txtOnce you enter the above command you will get the message as shown below.Start-Transcript -Path .\Sessionrecording.txtOutputPS E:\scripts\Powershell> Start-Transcript -Path .\Sessionrecording.txt Transcript started,  output file is .\Sessionrecording.txtBelow is the ... Read More

How to read the XML file in PowerShell?

Chirag Nagrekar
Updated on 11-Nov-2020 11:31:12

12K+ Views

Reading the XML file in PowerShell is easy. We have the below XML file for our example, Example                   Forest             Brown                         Street             Multi                         Forest             Yellow     Suppose this file is saved as Animals.xml to our current path and to read this XML file we ... Read More

How to pass arguments in Invoke-Command in PowerShell?

Chirag Nagrekar
Updated on 11-Nov-2020 11:25:40

13K+ Views

To pass the argument in the Invoke-command, you need to use -ArgumentList parameter. For example, we need to get the notepad process information on the remote server.ExampleInvoke-Command -ComputerName Test1-Win2k12 - ScriptBlock{param($proc) Get-Process -Name $proc} - ArgumentList "Notepad"OutputHandles NPM(K) PM(K) WS(K) CPU(s)  Id SI ProcessName PSComputerName ------- ------ ----- ----- ------  -- -- ----------- --------------   67      8  1348  7488   0.08 104    notepad     Test1-Win2k12In the above example, we are passing "Notepad" name as the argument to the command and the same has been caught by the $proc variable inside Param().If you have the multiple, check the below command to pass the multiple parameters.ExampleInvoke-Command ... Read More

How does string formatting work in PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:46:56

519 Views

To format string in PowerShell, you can use -F operator. When you use -F format, you need to provide the argument number in the curly brackets.ExamplePS C:\> $Str = "Hello PowerShell" PS C:\> "{0}" -f $str Hello PowerShellFor the multiple values, PS C:\> $Str = "Hello PowerShell" PS C:\> $str1 = "Rockstart" PS C:\> "{0} says {1}" -f $Str, $str1 Hello PowerShell says RockstartFrom the above example, we understood if we need to get the output for multiple variables using the -F operator then we can increment the number in curly brackets.To use the above output with the Write-Output command, ... Read More

How to find the MAC address of the system using PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:45:59

4K+ Views

There are several ways to find the MAC address (Physical Address) of the system using PowerShell.Using the Get-NetAdapter commandUsing this command, we can retrieve the MAC address of the network adapter.Using GetMac commandIpconfig commandWe need to use Ipconfig /all to retrieve the mac address of all the adapters.ExampleIpconfig /all | Select-String -Pattern "Description","Physical"Output

How to Resolve DNS address using PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:42:22

15K+ Views

To resolve the DNS address using PowerShell, we need to use the Resolve-DNS address command. This command works similarly to Nslookup command.To resolve the A record (Name -> IP), you can directly provide the hostname and by default, it will retrieve all the records for the particular address.ExampleResolve-DnsName -Name Test1-win2k12OutputName                            Type  TTL Section IPAddress ----                            ----  --- ------- --------- Test1-Win2k12.labdomain.local    A   1200 Answer 192.168.0.107-Name parameter doesn’t accept the multiple-input. Only the single ... Read More

How to install the PowerShell Active Directory module?

Chirag Nagrekar
Updated on 09-Nov-2020 09:40:04

794 Views

To install the active directory module using PowerShell, you need Remote Server Administrator Tools (RSAT) on the server. It should be available in the Roles and Features section of the windows server operating system as shown below and you can enable it from the GUI as well.If you can’t find the RSAT then you can download it from the below location, appropriate to your OS version.https://www.microsoft.com/en-us/download/details.aspx?id=45520Once you have the RSAT tool available in your system, you can use the PowerShell command to enable this feature. To get the Active Directory tools features available in the system, use the below command.ExampleGet-WindowsFeature ... Read More

PowerShell: Wait for the First command to finish

Chirag Nagrekar
Updated on 09-Nov-2020 09:37:19

1K+ Views

We know that PowerShell executes commands sequentially until we specify some parallel Jobs but sometimes the next command executes before the First command because the first command might be taking a long time to retrieve the data. In that case, if you want the previous command to finish first and then the next command to get executed, you can use PowerShell Job functionality.For example, we need to write a script to ask for the user input to terminate process ID but the program should retrieve the process IDs first.Example$job = Start-Job {Get-Process} Wait-Job $job | Out-Null Receive-Job $job $id = ... Read More

Advertisements