Posts

Showing posts with the label powershell

PowerShell Set-MSolUserLicense

I am trying to unassign a bulk of user's licenses from our Office365. I have all of the user's UserPrincipalName on a CSV file like so: That is what I tried to do: When I had only one user on the CSV file, it works ! But when I try to add more users to the exact file and in the exact same list, the command fails and give me this error: I doubled checked and made sure the it is indeed the correct license ( domain:StandartPack ) What else can I do? How can I make it work? You need to iterate each line in the csv at a time, at the moment you work with all of them at once, so try this: **EDIT: Try the following method as well (update if necessary) You will need to iterate through all of the licenses assigned and find the one you are looking to remove. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is sub...

Split an array of strings in to chunks of a maximum size

I'm attempting to ensure an array of unknown length is split in one-or-more arrays with a maximum of 20 elements. I've searched around and found several answers for similar questions based on arrays containing number sequences (or maybe I'm just missing something), but nothing for an array of strings. I've come up with a solution, but it seems a little convoluted and I feel it could probably be better. For example, take this array - And for the sake of this example, that's say I want only a maximum of two elements - So now I have an array of arrays - But... Can I achieve my goal in a more efficient way? Use a for loop, the range operator ( .. ), and the unary array construction operator ( , ): [array]$keys casts the key/value collection .Keys to a generic array (so that the index operator can be used on it). The expression $i..($i+$size-1) gives you the indexes from $i up to the index before $i+$size , i.e. the next $size elements from the array starting at pos...

WSUS Last status Report check in

So I am working with WSUS and I had an issue a couple of weeks ago under all my computers that none came back to report or at least the "Last Status Report" did not show for 8 days....(Picture attached) To solve this issue I reset the IIS and that did the job and the reports started to come in as usual. To avoid this error in the future I wish to write a Power Shell script that constantly checks that the "Last Status Report" are coming in on a regular basis. As you can see in the image the last status reports jump from the 10th to the 18th and nothing came back in and reported from the 11th to 17th. I am just getting started with POWERSHELL but have some experience with C++, JAVA and VBA. If anybody can help me or point me in the right direction would be great. Thanks in advance. This is what I have so far: I investigated in Microsoft help forums that one can obtain the collection of updates and their different states and times. I need something to monitor the statu...

$MyInvocation in a runspace Thread

A script (foo.ps1) creates a thread, and that thread creates more threads. Foo's thread is my control thread, and it creates one or more worker threads. The worker threads run a script block. The script block calls functions from a library-script. The library script has a configuration file. The script block loads the library-script by dot-sourcing it. When the script loads, the first thing it does is find its configuration file, which is in the script's directory. The code for that looks like... My problem is $MyInvocation doesn't appear to exist. As result, the library script can't find it's configuration file. I'm running Powershell 5.1 on Windows 10. The control thread was made in a runspace. The worker threads are made in a runspace pool. Does anyone know the rules around the automatic $MyInvocation variable in runspace threads? Create a file foo.ps1 and add the following to it: Run it. You should see something like the following... And, I think I just a...