August, 2013

  • PowerTip: Find Case-Specific Strings by Using PowerShell

    Summary : Use Windows PowerShell to find case-specific strings. How can I find a particular, case-sensitive word in a string? Use Select-String and specify the –CaseSensitive switch: "Hey Scripting Guy","hey scripting guy" | Select-String -Pattern 'hey' -CaseSensitive
  • Use PowerShell to Customize Server Manager

    Summary : Guest blogger, Rolf Masuch, talks about using Windows PowerShell to customize Server Manager. Microsoft Scripting Guy, Ed Wilson, is here. Today we have a guest post written by Rolf Masuch, who is a senior consultant for Microsoft in Germany. Today is Rolf’s birthday, and he wanted to start the celebration off right by sharing a couple of cool scripts with us. Take it away Rolf… When it comes to the new versions of Windows Server 2012 R2 and Windows Server 2012, one of my most-loved changes is to Server Manager. The new Server Manager Dashboard looks like this: Lots of documents have been written already about this new way of working. Today I’d like to share two extension scripts that I thought would be helpful for the community because when it comes to automating Server Manager, you cannot do two things: Add servers to your list of managed servers Create groups that contain a custom list of servers You will find the respective menu entries in Server Manager when you click Manage . But first, let’s look behind the curtain of Server Manager. It stores information in an XML file that is saved per user at this location: $ENV:APPDATA\Microsoft\Windows\ServerManager\ServerList.xml Additionally, it is useful to know that every time you close a running Server Manager instance, it can overwrite your scripted changes. We want to take care that before we make changes to the XML file, we close the Server Manager process. We also need to make all changes in an elevated process. When it comes down to writing additional entries to the file, you may think, “Hey, it is just XML, this is easy.” But when you look at the structure of the XML file, you see that this is not so simple. The following example is from a freshly installed system with one additional group: ServerManager.xml *** <?xml version="1.0" encoding="utf-8"?> <ServerList xmlns:xsd=" http://www.w3.org/2001/XMLSchema " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " localhostName="MyCloudComp001" xmlns="urn:serverpool-schema"> <ServerInfo name="MyCloudComp001" status="1" lastUpdateTime="2013-08-08T09:01:26.7659233+00:00" locale="en-US" /><ServerGroupInfo id="3" name="MyGroup" /> <ServerGroupMembership server="MyCloudComp001" serverGroupId="3" /> </ServerList> *** As you see from the initial lines, the XML structure is using an additional namespace that is...
  • PowerTip: Use PowerShell to Show Approved Verbs Group

    Summary : Use Windows PowerShell to show the group of approved Windows PowerShell verbs. How can I find the grouping information for a couple of approved verbs that I want to use to name my advanced functions? Use the Get-Verb function, and supply an array of verbs to the function: get-verb ping, receive
  • Use PowerShell to Log Changes to AD DS Attributes

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to log changes made to Active Directory Domain Services attribute values. Hey, Scripting Guy! We are in the process of merging a couple of resource domains, and we need to modify some user accounts prior to the move. I have been tasked with making the changes, and I plan to use Windows PowerShell to perform the actual work. I need to create before and after logs. The before log shows the value of the attributes that I am going to change prior to running the script, and the after log will show the value of the attributes after running the script. Can you show me how I might go about doing this? Thanks, Scripting Guy, you are the best! —CX Hello CX, Microsoft Scripting Guy, Ed Wilson, is here. This morning I am sitting on the lanai, and sipping a cup of English Breakfast tea. I put a bit of lemon grass, hibiscus flower, rose hips, spearmint, and a cinnamon stick in the tea. The flowers give it a citrus flavor, and the mint makes it very refreshing. The trick is that I only let it steep for three minutes, and that keeps it from becoming too bitter. It took me several tries to get this one just right. Because it is pretty early, it is not too hot or humid outside yet. I have my Surface RT, and am checking my scripter@microsoft.com email. So, CX, you did not specify how you want your logging to take place, but I decided that exporting to a CSV file would work out well. Then you could import it into Microsoft Excel if you want to do so. Finding the attribute and values The first thing to do is to create a little script that will populate an attribute with before values. I am going to populate the Post Office Box attribute, so I need to look it up in ADSI edit. I come up with the following (surprisingly, it is named postOfficeBox ): I write a little script to add values to this attribute. Here is the script: Import-Module activeDirectory $ou = "ou=testou,dc=iammred,dc=net" $i = 1 Get-ADUser -Filter * -SearchBase $ou | ForEach-Object { Set-ADUser $_ -POBox "Post Office Box $i" $i++ } Now I want to see how many different cities are represented by the users in the organizational unit (OU). I modify my script a bit and use the –Unique parameter from the Select-Object command. This is shown here: Get-ADUser -Filter * -SearchBase $ou -properties $properties | select l -Unique The following output tells me that I have three...
  • PowerTip: Use PowerShell to Display Replications in AD DS

    Summary : Use Windows PowerShell to display replication connections in Active Directory Domain Services. How can I use a cmdlet from the Active Directory module to display replication connections in AD DS? Use the Get-ADReplicationConnection cmdlet and select the ReplicateFromDirectoryServer property and the ReplicateToDirectoryServer property (this is a single-line command broken at the pipe character for readability): Get-ADReplicationConnection | select ReplicateFromDirectoryServer, ReplicateToDirectoryServer
  • Use PowerShell to Change Sign-in Script and Profile Path

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to modify the sign-in script and profile path in Active Directory. Hey, Scripting Guy! We are in the middle of an Active Directory migration (primarily moving our client computers from Windows XP to Windows 8). We are also consolidating our file servers and our profile servers. We have multiple sites, and in the past, each site had a one or more domain controllers, multiple file and print servers, and other stuff as needed. Now, we are collapsing that infrastructure into a single server running Hyper-V. Needless to say, our profiles will be moving to different servers, and we will also be changing our sign-in scripts. So I need an easy way to modify these settings for our users. The new servers will be based on the user’s city locations. Can you help? —RA Hello RA, Microsoft Scripting Guy, Ed Wilson, is here. Things have been busy around the Scripting House. I got up early to check the scripter@microsoft.com email and to write a couple of proposals for Windows PowerShell Saturday in Atlanta . According to Mark, I will be making two presentations—one for the beginner track and one for the advanced track. In addition, I have been working on my presentation that I will be conducting remotely for Windows PowerShell Saturday in Singapore . Find the attribute names The first thing we need to do is to find the ADSI attribute names for the profile path and for the sign-in script. I open up one of the user profiles and type some bogus information so that I can find the attributes in ADSI Edit. Here is the page from Active Directory Users and Computers: Now I navigate to the same user object in ADSI Edit and look up the ADSI property names. The names make sense: ProfilePath and ScriptPath. This is shown here: Get the information from AD DS Now I need to retrieve the information from Active Directory Domain Services (AD DS). I could do all this from inside the Windows PowerShell console, but I decided to use the Windows PowerShell ISE instead. It has better intellisense, and for something like this, it makes things a bit more readable. I decide to use a couple of variables to hold the organizational unit (OU) and the properties that I need to retrieve. I then use Get-ADUser to retrieve the information. Here is this portion of the script: Import-Module ActiveDirectory $ou = "OU=Testou,Dc=Iammred,Dc=Net" $properties = "ProfilePath...
  • PowerTip: Use PowerShell to Get DHCP Server Database Info

    Summary : Learn how to use Windows PowerShell to get the DHCP Server database information. How can I use Windows PowerShell to get the database information for a DHCP server if I do not know the name of the server? Use the ServerName property from the object returned by Get-DHCPServer to get the computer name, then use the Get-DhcpServerDatabase : Get-DhcpServerDatabase -ComputerName (Get-DhcpServer).ServerName Note The DHCP functions come from the DHCPServer module obtained via the RSAT tools for Windows Server 2012.
  • Add User Principal Names in Active Directory via PowerShell

    Summary : Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to add user principal names to users in Active Directory. Hey, Scripting Guy! We are planning for our Active Directory migration, and as part of that, I am reviewing users. The problem is that I found out that whoever set up our original installation did not assign values for user principal names (UPN). This will cause us a problem as we move to a federated environment. Can you offer an easy way to populate this value? —CG Hello CG, Microsoft Scripting Guy, Ed Wilson, is here. This morning I am sitting on our lanai and checking my scripter@microsoft.com email on my Microsoft Surface RT. I received an email from one of my friends in Hawaii. He was telling me about a Hukilau he went to over the weekend. From his description, it makes me want to grab the Scripting Wife and head out west on the next available flight. The big problem right now, is the weather. I prefer August in Australia to August in Hawaii—it is really hot there. In Active Directory Users and Computers, the UPN shows up as the user logon name. It displays the UPN in two different fields, as shown in the following image. To find the actual Active Directory attribute name, I add a bunch of AAAs to the user logon name, and select a domain from the drop-down list. I then go into ADSI edit and look up the value. I see the following: Searching for existing values I use the Get-ADUser cmdlet to look for existing values for the UserPrincipalName attribute. To find the value of the UserPrincipalName attribute, I have to specify it for the –Properties parameter. I specify the SearchBase of the organizational unit (OU), and I use the * filter. This is shown here: Get-ADUser -Filter * -SearchBase 'ou=testou,dc=iammred,dc=net' -Properties userPrincipalName The command and associated output are represented in the following image. Setting the UPN value I use the Get-ADUser cmdlet to retrieve all the users to set. I pipe the resulting user objects to the Foreach-Object cmdlet, and in the script block, I use the Set-ADUser cmdlet. The Set-ADUser cmdlet has a –userPrincipalName parameter that makes it easy to set the UPN. To create the UPN, I use a hardcoded domain name, and I get the user’s name from the Name attribute. I use parameter substitution and the –f format specifier to concatenate the user principal name. The command is shown here (this...
  • PowerTip: Use PowerShell to See Network Adapters Bound to TCP/IP

    Summary : Use Windows PowerShell 3.0 in Windows 8 to see network adapters that are bound to TCP/IP. How can I find all network adapters that are bound to TCP/IPv4 by using Windows PowerShell 3.0 in Windows 8? Use the Get-NetAdapterBinding function, pipe the results to a Where-Object cmdlet, and filter for the BindName equal to ‘tcpip’ : Get-NetAdapterBinding | where bindname -eq 'tcpip'
  • Adding Office Locations in AD DS with PowerShell

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to add office locations in Active Directory Domain Services. Hey, Scripting Guy! We are in the midst of a domain migration at work, and I need to clean up a number of attributes in Active Directory prior to our migration. Part of our issue is that we have attributes that are missing values, and I just hate to migrate empty stuff. Is there anything you can do to help? —TV Hello TV, Microsoft Scripting Guy, Ed Wilson, is here. I am listening to my customized Internet radio station with a cool app I found for Windows 8 in the Windows Store. It is really cool to be able to select my listening preferences. I have actually spent a bit of time and created a couple of special Scripting Guy stations. It all depends on what I am writing. For example, Active Directory Domain Services questions simply beg for a bit of classic New Orleans style jazz —or, that is just me. Jazz also goes well with spearmint, wintergreen, peppermint, and lemon grass with a spoon full of Gun Powder Green tea. So I have my tunes and my tea. I guess I will answer your question. First find the attribute The first thing I need to do is to find the attribute that is missing. I first look at the user in Active Directory Users and Computers. This is shown here: It seems that the Office attribute is missing from all of the user objects. I add a bunch of AAAAAs to the Office field so I can find the attribute in ADSI Edit. I check with ADSI Edit, and sure enough the Office attribute is named physicalDeliveryOfficeName as shown in the following image. Good, that makes it easy. I look around, and all of the cities are populated. So I check ADSI Edit, and I figure out that it uses a lower-case l — as in L for Location. This is shown here. Populating the Office field In my example, the office names are the same as the city names. So all I need to do is to read all of the city names from all users in the TestOU organizational unit and add the city value to the Office attribute. First, let me make sure I can get the cities for all users. This is shown here: Get-ADUser -Filter * -SearchBase 'ou=testou,dc=iammred,dc=net' -Properties l The command and its output are shown in the image that follows. As it turns out, I do not need to know the physicalDeliveryOfficeName attribute name because Set-ADUser has an –Office parameter. I compose the following command...
  • PowerTip: Use PowerShell to Report Network Adapter Binding

    Summary : Use Windows PowerShell 3.0 in Windows 8 to view network adapter binding information. How can I use Windows PowerShell 3.0 in Windows 8 to review network adapter binding information? Use the Get-NetAdapterBinding function and pipe the resulting information to the Format-List cmdlet: Get-NetAdapterBinding | Format-List *
  • Weekend Scripter: Run PowerShell Scripts from Remote File Share: Part 3

    Summary : Microsoft Scripting Guy, Ed Wilson, continues his discussion about running scripts from a remote file share. Microsoft Scripting Guy, Ed Wilson, is here. Some things should just be easier. For example, I should have access to client-side cmdlets to work with SharePoint. Many times, as a user, I need to accomplish repetitive tasks, and a few cmdlets could really come in handy. Running scripts from remote file shares should be easier as well. Easier? What am I talking about? Well when someone asks a question, there are so many “it depends,” “maybe,” and “whatever” stuff going on that it really makes what should be easy very complicated. For example, in a freshly created Windows Server 2012 forest, I created a share on the domain controller. I modified the script execution policy on the client, and I could run scripts from the share just fine. No configuration, no signing, no nothing. It just worked. But to make a proclamation would take hours of testing in all different sorts of variables. The easy way to run a script Note This is the third in a multipart series of posts. The first post was Running Scripts from a Remote File Share . The second post was Weekend Scripter: Run PowerShell Scripts from Remote File Share: Part 2 . For good background info about running Windows PowerShell scripts from a remote file share, check out the guest blog post written by June Blender and Judith Herman: How to Run PowerShell Scripts from a Shared Directory . The easy way to run a script from a remote file share is to use the Bypass methodology. This is not a security hole, because the script execution policy and the associated settings are not really security features—they are a security convenience. This means that they are in place to remind me to do the right thing—to encourage me to follow best practices. But they are not put in place to discourage getting the job done. So, all the discussion about the script execution policy and signed scripts can be bypassed if I need to do so. What is a common requirement? Well, running a script from a scheduled task, or from within a Group Policy Object. If the desktop and network configuration are complicated to the point of not knowing what will go on, I can use Bypass mode and still get my scripts to run. To illustrate this point, I change my script execution policy to Restricted . This is the way it comes out of the box. Scripts do not run. Using...
  • PowerTip: Change PowerShell Script Execution Policy

    Summary : Learn how a user can change the Windows PowerShell script execution policy. How can I change the Windows PowerShell script execution policy as simply an ordinary user? Use the –Scope parameter with the Set-ExecutionPolicy cmdlet and specify CurrentUser (the –Force parameter hides prompts from the cmdlet): Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
  • Weekend Scripter: Run PowerShell Scripts from Remote File Share: Part 2

    Weekend Scripter: Run PowerShell Scripts from Remote File Share: Part 2 Summary : Microsoft Scripting Guy, Ed Wilson, continues his discussion about running scripts on a remote file share. Microsoft Scripting Guy, Ed Wilson, is here. This week has been absolutely bizarre. I have been really busy working with a select group of Honorary Scripting Guys for upcoming blog posts. I must say, there is some absolutely way cool, knock-out stuff in the works. But of course, to make all of this streamlined, I had to set up a shared Office 365 SharePoint site, grant permissions, create views, test things out, and all of that. You know what? Dude, it was easy!!! As you may guess from the three exclamation points, I was surprised. I must say that I was dreading it. I will also say that it was so intuitive that I did not once have to use Help or search for How-To articles. It really makes sense, and it has actually been a fun project. As one twentieth-century philosopher said, “I love it when a plan comes together.” Examining script execution policy Note This is the second in a multipart series of posts. The first post was Running Scripts from a Remote File Share . For good background info about running Windows PowerShell scripts from a remote file share, check out the guest blog post written by June Blender and Judith Herman: How to Run PowerShell Scripts from a Shared Directory . By default when you open Windows PowerShell, the execution of scripts is disabled. This is because the default script execution policy in Windows PowerShell is restricted. To see the current script execution policy, use the Get-ExecutionPolicy cmdlet. For the current user, all you need to do is type the cmdlet name. This is shown here: PS C:\> Get-ExecutionPolicy RemoteSigned To see all of the execution policies, use the –List switch as shown here: PS C:\> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser RemoteSigned LocalMachine Unrestricted You can see that there are multiple levels to which the script execution policy can be set. An ordinary user can change the CurrentUser script execution policy (unless it is specified via Group Policy. In that case, it cannot be modified by a local user). When the execution policy is first checked, it is restricted; therefore, no scripts will run. In the following example, the execution...
  • PowerTip: Use PowerShell to Get DHCP Stats

    Summary : Learn how to use Windows PowerShell 3.0 in Windows Server 2012 to get DHCP statistics. How can I get an overview from my DHCP server running on Windows Server 2012? Use the Get-DHCPServerv4Statistics function: Get-DhcpServerv4Statistics -ComputerName DHCP1
  • Running PowerShell Scripts from a Remote File Share

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about running Windows PowerShell scripts from a remote file share. Microsoft Scripting Guy, Ed Wilson, is here. It is sort of official… There are at least three Windows PowerShell Saturday events coming up. They are listed on the PowerShell Saturday website. Atlanta and Singapore are already planning (I know, because I will be speaking at both events). The Charlotte event is still early in the planning stages (I will be speaking there also). Of course, don’t just take my word for it. Bookmark the PowerShellSaturday website, so you can keep up to date on all the events. First things first Note For good background info about running Windows PowerShell scripts from a remote file share, check out the guest blog post written by June Blender and Judith Herman: How to Run PowerShell Scripts from a Shared Directory . So I have this shared folder on one of my servers. I can open Windows PowerShell and use the Net View command to see all of the shares. I can then use the Get-ChildItem command ( dir is an alias) to view the files in the shared folder. This is shown here. If I want to look at the files in a GUI, I can type the path into Internet Explorer, and view the files in the File Explorer as shown in the following image. For a background, I happen to know that the remote server is running 32-bit Windows Server 2008. I also found out that the server is running Windows PowerShell 2.0. I did this by using the Invoke-Command cmdlet ( icm is an alias) as shown here: PS C:\> icm -ComputerName dc1 {$PSVersionTable} Name Value ---- ----- PSRemotingProtocolVersion 2.1 BuildVersion 6.0.6002.18111 PSCompatibleVersions {1.0, 2.0} PSVersion 2.0 CLRVersion 2.0.50727.4241 WSManStackVersion 2.0 SerializationVersion 1.1.0.1 Open script in ISE The cool thing is that I can open a Windows PowerShell script in the Windows PowerShell ISE on my 64-bit laptop (running Windows 8a and Windows PowerShell 3.0) from the remote file share. So I do the following: I open the Windows PowerShell ISE. I click File , then Open . In the Open dialog box, I type the UNC path to the remote file share and I press ENTER. I am now viewing the files from the share, as shown in the following image. I view (and edit if required) the script from the remote file share. When I am ready, I click the green triangle (or press F5) to run the script. At the top of the...
  • PowerTip: Use PowerShell to Rename Printers

    Summary : Learn how to use Windows PowerShell 3.0 in Windows 8 to rename a printer. How can I use Windows PowerShell 3.0 in Windows 8 to rename a printer? Use the Get-Printer function to retrieve the printer, and pipe it to the Rename-Printer function: Get-Printer -Name 'mynewlaser' | Rename-Printer -NewName 'myotherlaser'
  • Use PowerShell in Windows 8 to Remove Printers

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell 3.0 in Windows 8 to remove printers. Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I have been talking to various people from the Charlotte Windows PowerShell User Group all week about doing another Windows PowerShell Saturday. It is an awful lot of work, but I think we are going to do this again. The Windows PowerShell Saturday in Charlotte sold out within a few days, and there have been many positive comments about the event. That means that people found it to be a valuable experience. So we will have another Windows PowerShell Saturday. (By the way, if you want to have one where you live, let us know via scripter@microsoft.com .) To remove a printer with Windows PowerShell, I use the Remove-Printer function from the PrinterManagement module. There are two ways to use the Remove-Printer function: Remove-Printer [-Name] <String> [-AsJob [<SwitchParameter>]] [-CimSession <CimSession>] [-ComputerName <String>] [-PassThru [<SwitchParameter>]] [-ThrottleLimit <Int32>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]] [<CommonParameters>] Remove-Printer [-AsJob [<SwitchParameter>]] [-CimSession <CimSession>] [-PassThru [<SwitchParameter>]] [-ThrottleLimit <Int32>] -InputObject <CimInstance> [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]] [<CommonParameters>] What this means is that if I type the exact printer name, I can use the Remove-Printer function directly. It also tells me that I can pipe a printer object to the function. By pipelining a printer object, I can use wildcard characters. Begin with Get-Printer I usually begin things by using a Get type of command. So the first thing I do is use the Get-Printer function to see what printers are defined. The command is shown here: Get-Printer The command and its associated output are shown here: I can use a wildcard character to avoid typing a complete printer name as shown here: PS C:\> Get-Printer | where name -Like "my*" Name ComputerName Type DriverName ---- ------------ ---- ---------- myotherlaser Local Brother Laser Leg Typ... Or, I can type the exact printer name and supply it directly to the –Name parameter as shown here: PS C:\> Get-Printer -Name myotherlaser Name ComputerName Type DriverName...
  • PowerTip: Use PowerShell to Display Help for Module Cmdlets

    Summary : Use Windows PowerShell to display all Help for all cmdlets in a module. How can I see all of the Help examples for cmdlets from a specific module? After you have updated your Help in Windows PowerShell 3.0, use the Get-Command cmdlet to retrieve all cmdlets from a specific module, pipe the results to the Foreach-Object cmdlet, and use the Get-Help cmdlet inside the script block. Following is an example for the PrintManagement module: Get-Command -Module PrintManagement| Foreach-Object {get-help $_.name -Examples} Here is a shorter version of the same command: gcm -mo *print* | % {get-help $_.name -ex}
  • Install Printer Drivers with PowerShell in Windows 8

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell in Windows 8 to install printer drivers. Microsoft Scripting Guy, Ed Wilson, is here. This morning, it is rainy and overcast here in Charlotte, North Carolina, but it is pleasantly cool. The Scripting Wife migrated to the lanai and is sitting on her swing and checking Facebook on her Windows RT Surface. I am in my office checking email sent to scripter@microsoft.com . I am sipping a cup of English Breakfast tea with a cinnamon stick, lemon grass, hibiscus blossom, orange peel, and a bit of spearmint. It is a very refreshing cup of tea. When it comes to using Windows PowerShell to install print drivers, there is the long way and the short way. The long way is…well…long and rather complicated. The short way is easy. The difference in the two methods is not necessarily a conscious choice, but rather a function of the drivers already installed in Windows and the print device you intend to hook up. For example, we all know that Windows ships with a whole bunch of printer drivers already on the disk. They reside in the Windows\inf folder, and they all begin with the letters prn . The following script lists the printer drivers that ship with Windows. Get-ChildItem ((Get-Item Env:\systemroot).value+"\inf") -Exclude *.pnf -recurse | Where-Object { $_.name -match "prn" } | Sort-Object -Property name | format-table -Property name, length, creationTime, lastWriteTime -AutoSize Of course, one issue is a bit convoluted. The following image illustrates the output. The issue is that the names, such as prnbrcl1.inf, do not make too much sense. I can go to the Windows/inf directory, and open the .inf file in Notepad, and I am greeting with something that looks like the following. If I compare this output with the output from the advanced printer installation dialog box, I can see similarities. This is shown here. If I select a printer driver from the previous list, and click Next , the driver installs. I can verify this via the Get-PrinterDriver function, as shown here: Get-PrinterDriver The following image shows the command and its output. I can then use the Get-PrinterDriver function to retrieve the newly installed printer: Get-PrinterDriver -Name "Brother *" If I attempt to remove it, however, an error message appears, which states that it is being used by a printer. This command and the error message are shown here....
  • PowerTip: Use PowerShell to Get Printer Configuration

    Summary : Use Windows PowerShell in Windows 8 to find your printer configurations. How can I use Windows PowerShell in Windows 8 to get the printer configuration of all printers? Use the Get-Printer function, and pipe it to Foreach-Object and the Get-PrinterConfiguration cmdlet: Get-Printer | ForEach {Get-PrintConfiguration $_.name}
  • Use PowerShell to Create New Printer Ports

    Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell 3.0 to create new printer ports in Windows 8. Microsoft Scripting Guy, Ed Wilson, is here. One of the exciting things that is happening around the Scripting House is the appearance of new Windows PowerShell Saturday events. We have new events coming up in Atlanta, Singapore, and Charlotte. For information about these and other events, check out my site, Scripting Community . If you do not know what Windows PowerShell is, check out my blog post, Community: All about PowerShell Saturday . To programmatically create a working printer, there are at least three steps: Create the printer port. Install the printer driver. Install the printer (by using the printer port and the printer driver). Today I am talking about creating the printer port. Using PowerShell to work with printer ports Before I create anything, I like to know what I have going on with my computer. I can use the Get-PrinterPort function to list existing printer ports on my local computer: Get-PrinterPort I can also use this function to retrieve printer port information from a remote server running Windows Server 2008 and Windows PowerShell 3.0 as shown here: Get-PrinterPort -ComputerName dc1 The commands and the output from the commands are shown in the following image. Adding a new printer port To add a new printer port, I use the Add-PrinterPort function in Windows 8 or Windows Server 2012. By using the Add-PrinterPort function, I can add a local printer port, a TCP printer port, or an LPR printer port. Most of the time, if I am creating a local printer port, I want to print directly to a printer on the network. Doing this bypasses a print server. Therefore, in the case of large print jobs, I lose flexibility because my laptop must remain on to manage the large print job. But for short documents, it is fast. Also by printing directly to the printer, I can configure things the way that I want. By using Windows PowerShell, it is easy to create a TCP printer port. I use the Add-PrinterPort function, create a name for the port (the name does not matter, but it is best to use something that makes sense in the printing context). The IP address of the printer itself becomes the value for the PrinterHostAddress parameter. Here is the command I used: Add-PrinterPort -Name 'HP_Direct:' -PrinterHostAddress '192.168.1.88' I do not need to specify a value for the port...
  • PowerTip: Use PowerShell to Verify Secure Boot Policy

    Summary : Use Windows PowerShell to verify your Secure Boot policy in Windows 8. How can I verify that the Secure Boot policy is enabled in my computers running Windows 8? Use the Get-SecureBootPolicy cmdlet: Get-SecureBootPolicy
  • Use PowerShell to Test Remote Printers

    Summary : Learn how to use Windows PowerShell to test remote printers. Hey, Scripting Guy! I don’t know what it is, but for some reason printing still seems to be a pain. I mean, we have been using the network for a long time, and something as basic as printing still seems to be a problem. Whatever happened to the paperless office of the future? All we do is kill trees faster by using high-speed printers to print massive amounts of useless junk that no one reads. Anyway, for some reason, about half of our Help Desk calls are related to print issues. To be sure, some of it is user training issues—people trying to select the wrong feature for the wrong printer. But in all honesty, not all of the print problems are user related. For example, sometimes the print spooler seems to die, and we need to restart it. My Help Desk techs can open Computer management to stop and restart the spooler service, but I would like to do this via a script. Can you help? —RM Hello RM, Microsoft Scripting Guy, Ed Wilson, is here. We continue to get lots of rain here in Charlotte, North Carolina. Lots and lots of rain. The solar heaters for our pool are not doing much good these days. Oh well, maybe the sun will come out tomorrow. The print management module RM, you did not say if you are using Windows 8, so I am going to assume that you are. In Windows 8 (and in Surface RT, Surface Pro, and Windows Server 2012), there is a print management module called PrintManagement . It exposes the following commands: PS C:\> Get-Command -Module PrintManagement CommandType Name ModuleName ----------- ---- ---------- Function Add-Printer PrintManagement Function Add-PrinterDriver PrintManagement Function Add-PrinterPort PrintManagement Function Get-PrintConfiguration PrintManagement Function Get-Printer PrintManagement Function Get-PrinterDriver PrintManagement Function Get-PrinterPort PrintManagement Function Get-PrinterProperty PrintManagement Function Get-PrintJob PrintManagement Function Remove-Printer PrintManagement Function Remove-PrinterDriver PrintManagement Function Remove-PrinterPort PrintManagement Function Remove-PrintJob PrintManagement Function Rename-Printer PrintManagement Function Restart-PrintJob PrintManagement Function Resume-PrintJob PrintManagement Function Set-PrintConfiguration PrintManagement Function Set-Printer PrintManagement Function Set-PrinterProperty PrintManagement...