How to create Print queue with Powershell

Due to a new printserver rollout I write a powershell script to easily install network printers on the new Windows 2012 R2 printserver.

The script can be found here:

If the driver is not on driver store of your printserver, you need to install it before via GUI or using pnputil and Add-PrinterDriver:

pnputil -i -a "C:\Temp\Printers\Ricoh_UniDrv_plc6\x2DSPYP.inf"
Add-PrinterDriver -name "RICOH PCL6 UniversalDriver V4.12"

To create a new Printer Port and the Printer then just run this command:

.\New-ProvisioningPrinter.ps1 -ComputerName MYPRINTSRV -PrinterName PR01 -PrinterAddress -PrinterLocation "Italy, Milano, Reception" -PrinterComment "Asset Number: 01987" -PrinterDriver "RICOH PCL6 UniversalDriver V4.12"

Change ComputerName to your printserver, PrinterName to the name of new print queue you want to create, the PrinterAddress to the IP/HostName of network printer, PrinterDriver to the label of driver to use.

The script create the print queue PR01, shared with the same name and a printer port linked to that printer, named with the IP or HostName you specified on PrinterAddress parameter. SNMP is enabled too on “public” community.

You can also pipe a CSV file with PrinterName, PrinterAddress, PrinterLocation, PrinterComment columns to this script for bulk printers creation:

Import-Csv "C:\Data\Working\printers.csv" -delimiter ";" -Encoding UTF8 | .\New-ProvisioningPrinter.ps1 -ComputerName PRINTSRV

You have now all the printers installed to the new printserver. You need now to configure the default settings:

Set-PrintConfiguration -ComputerName MYPRINTSRV –PrinterName PR01 -PaperSize A4 -Color $False

this configure the PR01 printer with default Paper Size to A4 and to Black & White.

How to change Network Location in Windows 10

The easiest option is to use powershell. Open powershell with admin rights.

Get Network Name with this command:


The result on my case…

Name : Network 4
InterfaceAlias : Ethernet
InterfaceIndex : 3
NetworkCategory : Public
IPv4Connectivity : Internet
IPv6Connectivity : NoTraffic

Check the Name and the NetworkCategory.

Change the NetworkCategory (Location) from Public to Private with:

Set-NetConnectionProfile -Name “Network 4” -NetworkCategory Private

How to Change Remote App Icon on Windows 2012 R2

Changeing icon on RDS Remote App is possible only from Powershell.

Open administrative Powershell, import RemoteDesktop module and check first the current IconIndex and IconPath settings:

Import-Module RemoteDesktop

Get-RDRemoteApp -alias “MyApp” | fl

Then set the IconPath and IconIndex to the desired value. Found IconIndex counting the icons present on EXE,DLL,ICO until you reach the desired one starting from 0:

Get-RDRemoteApp -Alias “MyApp” | Set-RDRemoteApp -IconPath “C:\MyProg\MyProg.ico” -IconIndex 0

It’s possible also to change directly the .ico file you found on C:\Windows\RemotePackages\CPubFarms\CPubRemoteApps on the broker if you already have the icon on .ico format.

How to use Portable Visual Studio Code and GIT

I started to use Visual Studio Code as my primary Editor tool. I used portable version of Visual Studio Code and GIT to avoid installation and be able to quickly use different machines. For this purpose I also prefered to use “Workspace Settings” instead of “User Settings” in Visual Studio Code.

Download and install Visual Studio Code Portable from

Download and install Git Portable from

Open Visual Studio Code and create a “Workspace Settings” with path to portable GIT and in my case Proxy Settings:

// Place your settings in this file to overwrite default and user settings.
    // The proxy setting to use. If not set will be taken from the http_proxy and https_proxy environment variables
    "http.proxy": "",

    // Path to the git executable
    "git.path": "C:\\Data\\GitPortable\\App\\Git\\Bin\\git.exe"

If you develop in powershell with this repository make sense to add Powershell Extension ( and configure powershell as integrated terminal:

// 64-bit PowerShell if available, otherwise 32-bit

Open Visual Studio Code and initialize a GIT repository


Open GIT Portable, go to local repository path and config GIT repository:

git remote add origin
git config http.proxy "<a href=""></a>"
git config ""
git config credential.helper wincred

Check also to use Visual Studio Team Service as a provider.

How to solve Know Issue on MS16-072

Microsoft release MS16-072: Security update for Group Policy: June 14, 2016

MS16-072 changes the security context with which user group policies are retrieved. This by-design behavior change protects customers’ computers from a security vulnerability. Before MS16-072 is installed, user group policies were retrieved by using the user’s security context. After MS16-072 is installed, user group policies are retrieved by using the computer’s security context.

The issue was that all user Group Policy, including those that have been security filtered on user accounts or security groups, or both, may fail to apply on domain joined computers if the Group Policy Object is missing the Read permissions for the Authenticated Users group or if you are using security filtering and are missing Read permissions for the domain computers group.

To resolve this issue, use the Group Policy Management Console (GPMC.MSC) and follow one of the following steps:

  • Add the Authenticated Users group with Read Permissions on the Group Policy Object (GPO).
  • If you are using security filtering, add the Domain Computers group with read permission.


Doing that manually it’s a nightmare… but powershell can help. With this script you can deploy ‘Read’ permission for “Authenticated Users” on all GPOs or only where needed because “Domain Computers” group with ‘read’ permission and/or it’s a “Per-User Setting” GPO. If you what to be restrictive, enable -checkDomainComputer and -checkPerUserSetting.


How to Select an AD query on Powershell without AD cmdlets

I’m working on a script that should run on machines without powershell AD module, so I used objects from “System.DirectoryServices”. Working on that i experienced a bizarre performance problem. “Select-Object” on line 34 perform much better that the one on line 31:

…so I suggest to use Select-Object filtering on line 34