Category Archives: Tips

Powershell Tip #15: Use a BrowseFolder dialog for user input

Tip: You can specify a folder by using a GUI instead of manually copy/paste the path:

Powershell Tip #14: List, add and remove network drives

Tip: There are several ways to work with network drives: Cmdlets PSDrive WScript.Network COM object net.exe The following commands create a persistent drive (the drive will still here even after logout or reboot), list and remove the drive.

Note: When providing credentials, in this example I use the IP Address as it is a… Read More »

Powershell Tip #13: Prevent PowerShell from exiting once script finished

Tip: Sometimes you need to execute a Powershell script and keep the console open once the script is finished to see the result (or errors). You can use the parameter -NoExit : NoExit : Does not exit after running startup commands. powershell.exe -NoExit File 'C:\scripts\Get-DiskSpace.ps1'

Powershell Tip #12: Useful commands about Powershell profile

Tip: The automatic variable $PROFILE refers to Powershell profiles.

Note: A Powershell profile is just a ps1 file.

Powershell Tip #10: List the common parameters

Tip: You can list the common parameters: [System.Management.Automation.Cmdlet]::CommonParameters Powershell v4 Powershell v5 There are two new common parameters: InformationAction and InformationVariable. Note: To list the optional parameters: [System.Management.Automation.Cmdlet]::OptionalCommonParameters

Powershell Tip #9: Open file in a new tab in Powershell ISE

Tip: You can quickly open file(s) in a new tab in Powershell ISE with psEdit (or ise) :

3 tabs opened: # ise is an alias to powershell_ise.exe # psEdit is a function

Powershell Tip #8: OutVariable parameter

Tip: You can store the output of a command in a variable and at the sametime have this output on the screen. It is like “2 in 1”, you save and output. Note: no need to put the $ sign.

One line (needed to store and output on the screen) Two lines (needed to store and output on… Read More »

Powershell Tip #7: Convert WMI date to Datetime

Tip: You can convert WMI date (format DTMF Distributed Management Task Force) to DateTime:

Note: Use CIM cmdlets (available since PowerShell v3) instead of WMI cmdlets, moreover CIM return a more understandable datetime format : (Get-CimInstance -ClassName Win32_OperatingSystem).InstallDate MSDN: ManagementDateTimeConverter.ToDateTime Method