Assign access to users AAD application powershell or Graph API - powershell

I'm trying to give access to users on an application on AAD by powershell or Graph API. I have a list of 60 users and I don't want to do it by hand. I've investigate in AAD cmdleds but I didn't find anything useful for me. Is there any way for doing that?
Thanks a lot.

You can do so through PowerShell with a module from this blog post.
After you download the module, edit it, create a csv file containing your 60 users, run 4 cmdlets and you're done!
(Remember to restart PowerShell if you make an edit to the psm1 module in the middle of a PowerShell session, reimporting doesn't clear the cache.)

Related

Is it possible with PowerShell to find an author in Sharepoint and change it?

A little more context, I'm trying to use PowerShell to search through SharePoint for any files which have a particular Author.
We have an issue where if someone tries to delete a file that is authored by an ex-employee it alerts a different person that they did not have permission for the file to go to recycle bin for some reason and makes them permanently delete it instead. Below is a link of what they get:
Microsoft won't support it as they say they won't supply custom scripts so I was wondering if anyone here had any ideas?

How to share OneDrive files using Powershell?

I'd like to find an automatic way to share OneDrive files with a specific internal user, what's the best approach? My current scripts are using PowerShell, but that's not a hard requirement.
I've tried:
https://learn.microsoft.com/en-us/graph/api/driveitem-invite?view=graph-rest-1.0 - what's the best library to use for this? I've created an AzureAD app with the appropriate delegated permissions. In PowerShell, once I run Connect-MgGraph, what method can I run to call this?
https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitempermission?view=sharepoint-ps - but my OneDrive items aren't part of a list. Could they be? The folder permission works well: https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnpfolderpermission but I don't understand why there isn't a file one just like this folder one
I know the absolute URL of the file, the UPN of the internal user I want to directly share with, and I have owner permissions to the file. How can I do this?

Powershell Credentials Request Window Size

Powershell Noob here.
I have a basic Powershell script that requests user's credentials and then starts MMC programs for remote administration (example: dsa.msc). No issues with the script.
However, I am not happy with the size of the "Windows Powershell Credentials Request" window. I am using Get-Credential "$env:USERDNSDOMAIN\" but our domain name is pretty long.
What I would like:
(Preferred) Have the the domain name gathered in the script ($env:USERDNSDOMAIN) and the when the user is prompted for credentials; the username field will be empty and the user will only need to type their AD username. OR
Have the credentials be collected WITHIN the powershell window so there is enough room
Any assistance is appreciated. Thank you in advance.
You cannot change the default modal dialog/UI in Windows. If you want this control, you can write your own Winfomr/WPF GUI. deploy that for users to execute.
If you have not done this, use this free tool (though WinForm only - for now)...
Online Powershell Form Designer
...for your first effort at GUI design, but read up on GUI design (Winform and WPF) to know what this is about and the other steps you are going to need to do, to get it to do anything.
Youtube -
'PowerShell gui design'
As for your two bullet points. You are halfway there. Just do this:
Get-Credential "$env:USERDNSDOMAIN\$env:USERNAME"

Adding AD users as an Admin

Here's the situation. I'm am completely new to PowerShell so use small words...
I have a new user in Active Directory that I need to add to about 100 computers as efficiently as possible. My hope was that I could make a PowerShell script that would add the user either through a login script or remotely. I need to have a bit of precision control over this deployment because we don't want to push this user to every computer in the company.
Can PowerShell help me with this, and if not do you all have some sage advice that could help?
To add a user to the local administrators group using PowerShell:
([ADSI]"WinNT://./Administrators,group").Add("WinNT://your-domain/new-user,user")
Just replace the your-domain and new-user parts of the command with the appropriate values for your environment.

How do I add a PowerShell cmdlet or function to my machine so that it is always available?

If I find (or create) a new PowerShell cmdlet (or function), how do I add it to my machine?
Do I copy it to a particular folder?
Do I put its content in a particular file?
Do I need to authorize it, or sign it, or give it permission in some way?
I don't want to use it in just one session; I want it to be available whenever I use PowerShell on this machine.
As Alex mentions, any function defined in your profile or in a script that gets "dotted" into your profile will always be available. The same goes if you use Add-PSSnapin in your profile to add a snapin. The cmdlets in the snapin will always be available. For more information about profiles check out the help topic:
man about_profiles
However if you have a significant number of functions you may not want to load them until they are needed. In this case, you can organize functionality into scripts and then put those scripts into one or more directories that are in your path. You can then reference the script by name without specifying the full path or even the .PS1 extension. For more information about using scripts check out the help topic:
man about_scripts
PowerShell V2 introduces an even better approach to organizing functions and loading them on demand. The feature is called Modules and allows you to Import-Module by a simple name (rather than path) and to choose which functions and variable are made public versus which ones remain private. If you have V2, check out modules:
man about_modules
You should access the cmdlets through your profile script. That way, every time you access PowerShell, it gets loaded. See The Power of Profiles.