Microsoft Technologies Articles - Page 154 of 175

How to remove the mapped network drive using PowerShell?

Chirag Nagrekar
Updated on 11-Nov-2020 12:25:13

15K+ Views

To remove mapped drives from PowerShell on windows systems, you can use both PowerShell and cmd commands.Using the cmd commandYou can use the below command for a single mapped drive-by specifying the disk drive letter or by using the wildcard character (*).To remove a single mapped drive.Examplenet use K: /deleteOutputPS C:\WINDOWS\system32> net use K: /delete K: was deleted successfully.To remove multiple mapped drives together.Examplenet use * /deleteYou need to confirm removing multiple mapped disks together.OutputPS C:\WINDOWS\system32> net use * /delete You have these remote connections:     K:              \remoteshare\shared     M:              \remoteshare\shared folder Continuing will cancel the connections. Do you want to continue this operation? (Y/N) [N]: Y The command completed successfully. Using the PowerShell methodTo remove the mapped network drive with PowerShell ... Read More

How to map the network drive using PowerShell?

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

4K+ Views

You can map the network drive on the local and remote computers using several ways.Using cmd command.You can use the below command to map the network drive, here letter M, and the shared folder on the local computer.Examplenet use M: "\remoteshare\Shared Folder" PS C:\WINDOWS\system32> net use M: Local name        M: Remote name       \remoteshare\Shared Folder Resource type     Disk Status            OK # Opens           1 # Connections     1 The command completed successfully.To map on the remote computer.Invoke-Command -ComputerName RemoteComputer -ScriptBlock{net use k: "\remoteshare\shared"} Using the New-PSDrive command.You can map a network drive using ... Read More

How to display multiple outputs on an HTML webpage using PowerShell?

Chirag Nagrekar
Updated on 11-Nov-2020 11:57:39

1K+ Views

Consider you have multiple outputs to display on the webpage using PowerShell and we will use the Convertto-HTML built-in cmdlet for it but to display them properly, we first need to convert each part into fragment using –Fragment parameter.Let’s just take the simple example without the –Fragment parameter. In the below example, we are going to display the BIOS information, Local disk information, and Automatic but stopped services information.#To get the BIOS information Get-CimInstance Win32_BIOS | Select Name, Manufacturer, SerialNumber, Status, Version | ConvertTo-Html | Out-File ComputerInformation.html #To get the logical disk information Get-CimInstance Win32_LogicalDisk | where{$_.DriveType -eq '3'} | Select DeviceID, @{N='Total Size(GB)';E={[math]::Round($_.Size/1GB, 2)}}, @{N='Free size(GB)';E={[math]::Round($_.Freespace/1GB)}} | ... Read More

How to use CSS style in PowerShell HTML Output?

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

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

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

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

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

670 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

Advertisements