Archive for the ‘Powershell’ Category

I had an issue where Microsoft had issued a TS license pack key that had way too many licenses in it versus what was actually purchased through the CSP portal and I needed to remove some additional per user RDS licenses.

I had mixed results when trying to remove, and a lot of the information on the web I found was mainly for device CALS and not the user ones i needed to remove.

In the end I found a way to remove RDS CALS on Server 2016 (this will work on other server os’ too)

This command below displays the licensing info:

PS C:\Windows\system32> Get-WmiObject Win32_TSLicenseKeyPack|Select KeyPackId, ProductVersion, TotalLicenses, TypeAndModel|Format-List

KeyPackId      : 2

ProductVersion : Windows 2000 Server

TotalLicenses  : 4294967295

TypeAndModel   : Built-in TS Per Device CAL

KeyPackId      : 3

ProductVersion : Windows Server 2016

TotalLicenses  : 5

TypeAndModel   : RDS Per User CAL

KeyPackId      : 4

ProductVersion : Windows Server 2016

TotalLicenses  : 500

TypeAndModel   : RDS Per User CAL

This command below is what actually removes 495 licenses from keypack 4 ID

Invoke-WmiMethod -Class Win32_TSLicenseKeyPack -Name RemoveLicensesWithIdCount -ArgumentList 4,495

__GENUS          : 2

__CLASS          : __PARAMETERS

__SUPERCLASS     :

__DYNASTY        : __PARAMETERS

__RELPATH        :

__PROPERTY_COUNT : 1

__DERIVATION     : {}

__SERVER         :

__NAMESPACE      :

__PATH           :

ReturnValue      : 0

PSComputerName   :

Re-run the command to check and confirm the licenses have been removed from the targetted keypack ID.

Get-WmiObject Win32_TSLicenseKeyPack|Select KeyPackId, ProductVersion, TotalLicenses, TypeAndModel|Format-List

KeyPackId      : 2

ProductVersion : Windows 2000 Server

TotalLicenses  : 4294967295

TypeAndModel   : Built-in TS Per Device CAL

KeyPackId      : 3

ProductVersion : Windows Server 2016

TotalLicenses  : 5

TypeAndModel   : RDS Per User CAL

KeyPackId      : 4

ProductVersion : Windows Server 2016

TotalLicenses  : 5

TypeAndModel   : RDS Per User CAL

Connect to Exchange Online through Windows PowerShell with administrator credentials (when it prompts for username and password, your username is your email address for office 365/EXO admins). You can make a PS script to connect to exchange online rather than running them individually).

 

Notes: PS needs to be able to run scripts, if you get an error trying to run a command, try running this command first to enable execution of commands from PS:

 

Set-ExecutionPolicy RemoteSigned


Then try connecting using below

 

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session


Get a users mailbox’s current permissions

Once a connection has been established run the following PowerShell command to check users mailbox permission settings:

Get-MailboxPermission -Identity examaple.user1@company.com

(You will see the something similar to below in your PS window showing access rights for users)

 

pic1

 

 

 

Adding access to a another users mailbox

 To add access to another users mailbox you would type the below command, the first email address in the command is the user that you’re granting access to the second users mailbox. So the first user will have access to and when the outlook client is opened next, user 1 would see user 2’s full mail box inside user 1’s outlook client.

Command:

Add-MailboxPermission -Identity example.user1@company.com -User example.user2@company.com -AccessRights FullAccess 

 

 

pic2

 

Once added run the get command again to and check for the username of the user you just granted access to in the list to ensure command completed ok. Once confirmed exit the PS session if you’re finished using EXO by running the following command to close your PS session, otherwise you may use up all your PS sessions and have to wait for them to time out.

 

Remove-PSSession $Session

 

Removing Mailbox access from a user

Occasionaly there may be a request to remove a users access to another mailbox, so for removing we do something similar to what we did above with remove at the start of the command

 

1)      Remove-MailboxPermission -Identity example.user1@company.com -User example.user2@company.com -AccessRights FullAccess

 

 

pic3

 

 

 

Client ConfigMgr console Properties

%windir%\System32\CCM\SMSCliUI.exe
%windir%\SysWOW64\CCM\SMSCliUI.exe

Run Advertised Program (x64 & x86)

%windir%\System32\CCM\SMSRAP.CPL
%windir%\SysWOW64\CCM\SMSRAP.CPL

Task Sequence Progress Bar (x64 & x86)

%windir%\System32\CCM\TsProgressUI.exe
%windir%\SysWOW64\CCM\TsProgressUI.exe

SMS Agent Host Restart (x64 & x86)

%windir%\System32\CCM\CcmRestart.exe
%windir%\SysWOW64\CCM\CcmRestart.exe

SCCM (ConfigMgr) Client Repair – Command Line/ VB script / Powershell

%windir%\System32\CCM\ccmrepair.exe
%windir%\SysWOW64\CCM\ccmrepair.exe

—-policy.vbs—————-

On Error Resume Next
Dim oCPAppletMgr
Set oCPAppletMgr = CreateObject(“CPApplet.CPAppletMgr”)
Dim oClientActions
Set oClientActions = oCPAppletMgr.GetClientActions()
Dim oClientAction
For Each oClientAction In oClientActions
If oClientAction.Name = “Request & Evaluate Machine Policy” Then oClientAction.PerformAction
End If
Next
———————————————–
Powershell:

————-
Code Snippet

function repairclient([String] $strComputer)
{
$SMSCli = [wmiclass] “\\$strComputer\root\ccm:sms_client
$SMSCli.RepairClient()
}
———————————————–