Remove 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

Map 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

Get Mapped Drives Using PowerShell

Chirag Nagrekar
Updated on 11-Nov-2020 12:00:32

21K+ Views

There are few methods to get the mapped network drive using PowerShell.CMD command method.You can use the cmd command net use in PowerShell to get the mapped drives.net useOutputPS C:\WINDOWS\system32> net use New connections will be remembered. Status       Local     Remote                    Network ------------------------------------------------------------------------------- OK           K:        \localhost\shared folder Microsoft Windows Network OK           L:        \localhost\Shared        Microsoft Windows Network The command completed successfully.To get the mapped drives on the remote computer, Invoke-Command -ComputerName RemoteComputer -ScriptBlock{Net use} OrInvoke-Command -ComputerName RemoteComputer -ScriptBlock{Invoke-Expression -Command "Net use"}PowerShell WMI and CimInstance method.You can also use the ... Read More

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

Use CSS Style in PowerShell HTML Output

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

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

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

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

Read 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

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

Select Multiple DataFrame Columns Using RegExp and DataTypes

Kiran P
Updated on 10-Nov-2020 10:04:29

800 Views

DataFrame maybe compared to a data set held in a spreadsheet or a database with rows and columns. DataFrame is a 2D Object.Ok, confused with 1D and 2D terminology ?The major difference between 1D (Series) and 2D (DataFrame) is the number of points of information you need to inorer to arrive at any single data point. If you take an example of a Series, and wanted to extract a value, you only need one point of reference i.e. row index.In comparsion to a table (DataFrame), one point of reference is not sufficient to get to a data point, you need ... Read More

Advertisements