Powershell Get-Process missing parameter? - powershell

Currently I'm working on Windows Server 2012 R2 with Powershell 4.0 and can execute Get-Process -IncludeUserName while using elevated user rights as an admin. But when I try running the same command on a Windows Server 2008 R2 with Powershell 3.0 while using the same elevated user rights, the parameter -IncludeUserName isn't found. What's missing on the 2nd system for executing the command?

According to the Technet Article for get-process the -IncludeUserName parameter was not available in the get-process cmdlet until Powershell 4. You'll need to install the updated version in order to gain access to that feature.

It seems the difference between V3 and V4 is that V4 brings the additional ability to include the username of the process.
I don't have V3 to test with, but I do have V2, and it's not available there.

Related

New-ExoPSSession: Index was out of range

Im developing a script that connects to Exchange Online Microsoft 365, but when the script executes the cmdlet "Connect-ExchangeOnline", it ends with errors.
The specific instruction is:
Connect-ExchangeOnline -Organization $myTenant -AppId $AppId -Certificate $myCert
The variables in the parameters are correct, the error says:
New-ExoPSSession: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
I can load the module succesfully. The script connects to Exchange Online trough a cert installed in my machine, my script can read it without issues.
I'm running this script in Powershell V4 and .Net Framework 4.7.1. If i execute the same script in another machine with PowerShell V5.1 I can connect to Microsoft 365 Exchange Online succesfully. I tried with a lower version (ExchangeOnlineManagement 1.0.1) but this version hasn't got those parameters (Organization, AppId, etc...), I'm now using 2.0.3 version. I not sure if you can upgrade Powershell to 5.1.
Does anyone know why i can't connect to Exchange Online?
I've been struggling with this issue, and I finally found a solution.
Turns out running Import-Module ExchangeOnlineManagement before Connect-ExchangeOnline causes this error.
Removing Import-Module ExchangeOnlineManagement was enough to allow Connect-ExchangeOnline to connect without the New-ExoPSSession: Index was out of range error
EXO V2 is only supported on PowerShell 5.1 and later. If you want to use PowerShell 4.0 you will have to use EXO V1.
I'm not familiar enough with the EXO module to how or whether you can use EXO V1 in your current environment. If V2 is required for modern Exchange Online management then you will need to upgrade your nodes to use WMF 5.1 or install PowerShell Core (7+) and use EXO V2 from there.
PowerShell Core installs in parallel to Windows PowerShell so there is less of a risk of impacting other code which requires PowerShell 4.0 if you go this route.
I am using Windows PowerShell 5.1 and this seems to be an issue that's introduced in ExchangeOnlineManagement version 2.0.4.
Downgrading to 2.0.3 worked for me.
PowerShell needs to be started in elevated mode. However, my error was caused by RunAs with a domain admin account. Using RunAs with a local admin account works. YMMV.

Get-PnPProvisioningTemplate is not recognized as the name of a cmdlet

I am learning SharePoint and more specifically provisioning with PowerShell. I can't use cmdlets as Get-PnPProvisioningTemplate or Apply-PnPProvisioningTemplate, when execute them PS return that are not cmdlets. I don't know if I need to install something.
#Felipe,
These cmdlets are existed in legacy PnP but replaced by a new cmdlet in the current PnP.
Upgrading from the Legacy version of PnP PowerShell | PnP PowerShell
PnP PowerShell | PnP PowerShell
And the new corresponding cmdlet is:
Invoke-PnPSiteTemplate
More reference:
https://github.com/pnp/powershell/issues/285
BR
You need to follow the PnP.Powershell Documentation (https://github.com/pnp/powershell) that links you to the installation guide (https://pnp.github.io/powershell/articles/installation.html)
Basically you need to run Install-Module -Name "PnP.PowerShell" from a powershell console

SCCM Powershell Script Package

I have created a package in SCCM 2012 that should deploy and run a powershell script. I have looked at a previous post on here Other Post but there wasn't any information.
In the Program Command Line, I have the following command:
powershell.exe -ExecutionPolicy Bypass -force -WindowStyle Hidden .\PowershellUpdateScript.ps1
I am targeting a test group and setting it to deploy immediately however when I check the deployment status, it shows as status "In Progress" and Description "Received". It has been that way for over 2 hours. I am not sure where the issue is.
I know that the Scripts feature is there and super convenient but the client powershell version needs to be a minimum version 3. The irony is that this package will update client powershell versions.
Any suggestions or advise would be greatly appreciated.
Since you are updating the powershell version, instead of using a powershell script you should download the MS update package for the version of powershell.
You can then use the wusa.exe command to deploy the update. Then use this ps command as a detection method
Get-WmiObject Win32_QuickFixEngineering -filter "HotFixID='KB#######'"

Powershell 4 compatibility with Windows 2008 r2

In my environment I have a single server that has access to pretty much my entire network. That server is running Windows 2008 r2, and I have upgraded Powershell to version 4.0. The question I have is this... Can I run cmdlets from that machine on other machines that are version 4 specific?
For instance, when I am using Powershell, even though it is version 4, it doesn't give me an intellisense autocomplete for "Get-Volume" like it would on a 2012 r2 machine. I understand that it won't run on that machine because the infrastructure won't allow for it, but what about a 2012 r2 machine remotely?
I am looking to run batch scripts from there for various purposes.
First, this is probably a ServerFault-question as it's related to server-administration.
PowerShell 4.0 installed on 2008 R2 can't run 2012 cmdlets on a 2012 R2-machine like Get-Volume -ComputerName My2012Server, because the cmdlets doesn't exist on your 2008 R2 machine. However, you should be able to invoke the cmdlet on the 2012 R2-server, like:
Invoke-Command -ComputerName My2012Server -Scriptblock { Get-Volume }
Be aware that you would not get autocomplete support when writing it as the commands and help files aren't installed on your 2008 R2-server
Import-PSSession is also a possibility if your gonna run the commands interactively. For a script I would probably still use Invoke-Command.
Get-Volume in your example is available only on Windows Server 2012 and above. So, it won't auto-complete on a 2008 R2 system. You can use PowerShell implict remoting.
Using implict remoting, you can import all cmdlets from a remote system into a local session and use them as if they are available on the local system.

'Set-AdfsGlobalWebContent' is not recognized as the name of a cmdlet

I am trying to change company name using 'Set-AdfsGlobalWebContent' of powershell 4.0 .
I am using power-shell ISE but I am not able to get this command.
I am working on windows server 2012 R2
Anybody explain me Why that command is not showing in intelligence? is I am missing something?
after executing this command forcefully it gives "'Set-AdfsGlobalWebContent' is not recognized as the name of a cmdlet" error.
Thanks in Advance !!!
From technet:
To use these cmdlets you must have previously installed the AD FS server role. This can be done using the Add Roles and Features Wizard in Server Manager or optionally, you can use the Install-WindowsFeature AD-Federation-Services cmdlet at a Windows PowerShell prompt to add the role.