The Journey To PowerShell 7
In this issue:
- Overview
- Introduction
- Code Planning
- Deprecated Commands
- Deprecated Remoting
- Deprecated Features
- Find-Deprecated
- Summary
Overview
This is the beginning of a series of articles that will provide guidance and suggestions for making the transition from managing your environment with Windows PowerShell to PowerShell 7.
Introduction
At long last we now have official word from Microsoft that Windows PowerShell is history and the future is PowerShell 7. Although that "future" has actually been reality for several years. But now we've been given fair warning that we should be preparing for a PowerShell 7 world. Yes, there are some deployment issues that Microsoft has to work out, and we're trusting the other Microsoft product teams and third-party vendors will do the necessary work to transition to PowerShell 7.
You too need to begin the transition work if you haven't already. Over the next few newsletters I want to share my thoughts on how to approach this task. Microsoft has plenty of documentation already on the topic and I'm sure there will be more. I expect that some of my advice will overlap with Microsoft's.
Code Planning
The move to PowerShell 7 is your opportunity to re-visit how you want to incorporate PowerShell into your management strategy. I suspect that a lot of your current PowerShell usage simply evolved over time. It may have even begun before you started working at your organization. It wouldn't surprise me that a PowerShell solution was deployed to solve specific needs as they arose. Now is your chance to examine the "big picture" and decide how and where to use PowerShell.
You should be able to execute much of your PowerShell management code from your administrator desktop, using remoting to manage your environment. In some organizations, this might be a centralized management server or "jump box". In either event, think of this as the client. You should be able to use PowerShell 7 today from the client to remotely manage your network, even if the servers are only running Windows PowerShell. There are a few things to watch for with this type of cross-version remoting which I covered a few months ago.
While I prefer managing from the client, I can appreciate there will be situations where you need to initiate the code on the remote server. You, or your predecessor, may have done this for performance. However, you might take advantage of thread jobs or ForEach-Object -parallel to achieve similar results from the client. You need to decide what PowerShell tasks have to run on the remote server and clearly understand why.
Deprecated Commands
The easiest part of the transition process is identifying deprecated commands in your code. These are commands from Windows PowerShell 5.1 that don't exist in PowerShell 7. You can technically still run many of these commands in a PowerShell 7 session on your computer, but you are actually running them through a compatibility PSSession on the local host to a Windows PowerShell 5.1 runspace. If you haven't done so already, you should replace these commands in your PowerShell management code and scripts with PowerShell 7 replacements. Unfortunately, not every deprecated has a specific PowerShell 7 alternative. You may have to develop some alternatives yourself. Over the next few months, I will see what I can do to help fill in the gaps.
EventLog Management
In PowerShell 7 you will find that all of the traditional event log management commands no longer exist. Are you currently using any of the following in your scripts?
Get-EventLogLimit-EventLogNew-EventLogClear-EventLogRemove-EventLogShow-EventlogWrite-EventLog
If so, you need to transition to newer alternatives. The big one is Get-EventLog, which only works with classic event logs. That alone is a limitation you should want to overcome. You need to begin using Get-WinEvent. I especially encourage you how to use the filtering parameters to improve performance.
I always found Show-EventLog handy, but you can just as easily run eventvwr.msc at a prompt to open the event log viewer. The PowerShell command made it easy to connect to a remote computer, but you can also use eventvwr.msc /computer:<computername>. Note that this requires that firewall ports are open for Remote Event Log Management.
The other Windows PowerShell commands will require extra work to replace which I'm not going to get into today.
WMI
It should be common knowledge that the WMI commands from Windows PowerShell do not exist in PowerShell 7:
Get-WMIObjectInvoke-WMIMethodRegister-WMIEventRemove-WMIObjectSet-WMIInstance
WMI still exists and isn't going anywhere. What changes is how we connect to and query the WMI database remotely. This is the role of Get-CimInstance and related commands. Fortunately, the parameters are very similar.
PS C:\> Get-WmiObject -Class win32_operatingSystem -Property CSName,Caption,InstallDate -ComputerName Cadenza | Select Caption,CSName,InstallDate
Caption CSName InstallDate
------- ------ -----------
Microsoft Windows 11 Pro CADENZA 20250319171444.000000-240
PS C:\> Get-CimInstance -ClassName win32_operatingSystem -Property CSName,Caption,InstallDate -ComputerName Cadenza | Select Caption,CSName,InstallDate
Caption CSName InstallDate
------- ------ -----------
Microsoft Windows 11 Pro CADENZA 3/19/2025 5:14:44 PM
You might even be able to get by with simply replacing Get-WmiObject with Get-CimInstance since you can use the shortened -Class parameter with the latter. However, the output will vary, especially with datetime values. And remember that Get-CimInstance doesn't return an actual object so lose direct access to WMI methods. For that you'll need to use Invoke-CimMethod.
Remember, I'm not providing a complete transition plan, only identifying areas you need to be aware of.
Deprecated Remoting
Another major element, and one that is a bit more subtle is how some commands connect to remote computers. In Windows PowerShell, commands with a -Computername parameter are often connecting to a service or remoting endpoint that is using RPC/DCOM or some other legacy remoting protocol. These commands are not using PowerShell remoting. The help documentation should explain this.
PS C:\> help Get-Service -Parameter Computername
-ComputerName [<system.string[]>]
Gets the services running on the specified computers. The default is the local computer.
Type the NetBIOS name, an IP address, or a fully qualified domain name (FQDN) of a remote computer.
To specify the local computer, type the computer name, a dot (`.`), or `localhost`.
This parameter does not rely on Windows PowerShell remoting. You can use the **ComputerName**
parameter of `Get-Service` even if your computer is not configured to run remote commands.
Required? false
Position? Named
Default value
Accept pipeline input? false
Accept wildcard characters? false
You won't see these parameters in PowerShell 7.
PS C:\> Get-Command Get-Service -Syntax
Get-Service [[-Name] <string[]>] [-DependentServices] [-RequiredServices] [-Include <string[]>] [-Exclude <string[]>] [<commonparameters>]
Get-Service -DisplayName <string[]> [-DependentServices] [-RequiredServices] [-Include <string[]>] [-Exclude <string[]>] [<commonparameters>]
Get-Service [-DependentServices] [-RequiredServices] [-Include <string[]>] [-Exclude <string[]>] [-InputObject <servicecontroller[]>] [<commonparameters>]