PoweShell
14 TopicsAssigning groups to AD user.
Hello everyone, I have the following situation: In my work we are always hiring people and depending on their position they may be assigned to different groups. So the process of creating users and assigning them to groups has become a nightmare because my team always gets it wrong, so I either have to add or remove a group. So it occurred to me to create a kind of template to make sure that when they create a user for a specific area they put the groups that corresponds, however still have been wrong, so it occurred to me that it might be possible to create that template in files and through a PowerShell script assign the groups to the user, is that possible? Thank you in advance,1KViews0likes2Commentswhat would be powersheel command for getting backup status of azure vm
I am running command to get the backup status of azure vms. in which I have to select option all the time like inprogress, completed, failure. please help me the command which will show the status, whatever it is. I am using the below command- Get-AzRecoveryServicesBackupJob -Status InProgress -VaultId /subscriptions/f30d-46c7-8676-e34f9090bcc8/resourceGroups/abc/providers/Microsoft.RecoveryServices/vaults/vault803 and also there is possibility, that I can get the output for 2 days from current days.?1.1KViews0likes4CommentsPowershell and filtering results from cmdlest into CSVs
Hi everyone, I need to have a script that outputs a CSV list, to be used for a mail merge, with the last login and the alternative emails (and other useful info for the mail merge), so I can mass mail anyone that has not logged in yet. I have stumbled my way into creating a script, with lots of help and cobbled together from around the internet, now I am just missing a piece, which is to filter out users that have not logged in yet, as in have no data in the LastSignInDateTime field. This is the script: param($path="$PSScriptRoot\reports",$pwdnochangedindays = 480) cd $path Start-transcript $cohort = read-host "Enter cohort to audited" Connect-MgGraph -Scopes "Directory.ReadWrite.All", "Directory.AccessAsUser.All","User.Read.All","AuditLog.Read.All" Select-MgProfile -Name beta $MSGProps = @( 'id' 'displayName' 'CompanyName' 'State' 'OfficeLocation' 'department' 'signInActivity' 'userPrincipalName' 'userType' 'createdDateTime' 'accountEnabled' 'passwordPolicies' 'mail' 'lastPasswordChangeDateTime' 'OtherMails' ) $MSGSplat = @{ Filter = "userType eq 'Member' and AccountEnabled eq true and startsWith(State, '$cohort')" all = $true Property = $MSGProps } $MSGUser = Get-MgUser @MSGSplat $Results = Foreach ($SingleMSG in $MSGUser) { [pscustomobject]@{ Id = $SingleMSG.id DisplayName = $SingleMSG.displayName CompanyName = $SingleMSG.CompanyName State = $SingleMSG.State OfficeLocation = $SingleMSG.OfficeLocation Department = $SingleMSG.department UserPrinciple = $SingleMSG.userPrincipalName UserType = $SingleMSG.userType Created = $SingleMSG.createdDateTime Enabled = $SingleMSG.accountEnabled Mail = $SingleMSG.mail PasswordChange = $SingleMSG.lastPasswordChangeDateTime PasswordPolicy = $SingleMSG.passwordPolicies LastSignInDate = $SingleMSG.signInActivity.LastSignInDateTime LastNonInteractive = $SingleMSG.signInActivity.LastNonInteractiveSignInDateTime OtherMails = $SingleMSG | select-object -expand OtherMails } } $Results | Export-Csv -path "$path\aad_user_report_$((Get-Date -format "dd-MMM-yyyy"))_$cohort.csv" -notypeinformation write-host "Report can be found here $path" Stop-transcript # Based on chadmcox create-AADMGUserReport.ps1 # https://www.reddit.com/r/PowerShell/comments/vlrvca/expandproperty_csv_exporting_and_general_noobness/ # https://www.reddit.com/r/PowerShell/comments/vi8rcv/getting_a_list_of_all_users_last_login_status_and/ It produces a CSV like this: No idea how to do that, I have tried to add $results | where-object {$_.LastSignInDate -ne $null} | Export-Csv -path "$path\aad_user_report_$((Get-Date -format "dd-MMM-yyyy"))_$cohort.csv" -notypeinformation to the export oart of it , but no results from that. Any suggestions on how to get only people with no log-ins included?2.1KViews0likes9CommentsHow to compare two xml files and display the difference side by side.
$baseServer="C:\Store\PS\referrencexml.xml" $Server2Compare="C:\Store\PS\differencexml.xml" $boutput = Compare-Object -ReferenceObject (Get-Content -Path "$baseServer") -DifferenceObject (Get-Content -Path "$Server2Compare") Above command shows the difference between two files in the below format(Output1), but I need to display the difference in side by side like Output2. So, if someone could help me with an idea or sample code/script to get the output in two different column side by side, it will be very helpful. Output1: Input Object Side Indicator <genre></genre> => <genre>Fantasy</genre> <= Output 2: Reference File Difference File <genre></genre> <genre>Fantasy</genre>50KViews0likes6Commentsget-content and foreach loop
Hi I am trying to set permissions to all GPOs names in the file. I got the first PS script working by using -eq to name of a GPO in the file, but i need to set permissions to all GPOs in the file . I cant seems to figure it out . what am i doing wrong? Thanks in advance for your help! First script works just for one GPO $gpos =Get-Content "D:\gpolist1.txt" $gpos | foreach { if ($_ -eq "test") { Set-GPPermission -PermissionLevel GpoEditDeleteModifySecurity -TargetName "GPOAdmins" -TargetType Group $_ } } Not working , need to set permissionsfor all GPOs in the file $gpos = get-content "d:\gpolist1.txt" Write-Output $gpos foreach ($gpo in $gpos) { #call displayname if ($_ -eq $gpos) {Set-GPPermission -PermissionLevel GpoEditDeleteModifySecurity -TargetName "GPOAdmins" -TargetType Group $_ } else { write-output "no result" } }5KViews0likes3CommentsProvisioning Module not installed
Hi Community, I am really not a guy that starts asking help quick, but I have been searching on this issue for 6 hours now and cant find any information or fix for it, as it seems that it should not happen that you do not have the Provisioning Module as it is some sort of base module? But when I do: "Get-Module -ListAvailable" It does not list Provisioning as a module (Provisioning Module | Microsoft Docs) I also cant seem to install it manually. Any of the cmdlets also does not work (LikeInstall-ProvisioningPackage) My Powershell version is 5.1 so that is not the problem. Windows version 1607 (Windows 10 2016 LTSB) I cant find any information about why it would be missing or what the requirements are for having it. Nobody seems to have this issue. Does anyone know how to get it installed or know a reason why you should not have it? Thanks in advance!1.1KViews0likes1CommentExport Results To Individual Files
Hello I am trying to export .xml files from a list of servers so it creates a separate file for each server in a loop. But the problem is it looks like the loop would overwrite the results from each server in the loop to the same output file. I have been searching but cannot find a way to do what I want it to do. Here is what I have for the scrip. $computers = get-content .\servers.txt foreach ($computer in $computers){ Export-DhcpServer -ComputerName $computer -File "C:\DHCP_EXPORT\DHCP-Config.xml" -Force } Can someone tell me how I can get this to create a separate .xml file for each server in the servers.txt file? Its hard to search for a solution for this in Google so I though I could get some help here. Thanks in advance!!Solved992Views0likes2CommentsPS array performance >40K entries
Hi I'm trying to find the fastest way to search a large array (40K entries) for a value. However, I'm struggling with the way in which the array is working. I read in all AD users as shown below $AllADUsers = Get-ADUser -Filter "*" -properties SAMAccountName, DisplayName, UserPrincipalName, Company, Office,Department,Manager,Description,Created,LastLogonDate,EmployeeType,Info -Server$ADServer-Credential$c |selectSAMAccountName,DisplayName,UserPrincipalName,Company,Office,Department,Manager, Description,Created,LastLogonDate,EmployeeType,Info Now this is why I have a query If I search the array using the .Contains method it finds the entry in around 2ms $AllADUsers.Contains($SearchID) If I then try to pull the data for the record using the "where" method it takes 1000ms $AllADUsers.Where({$_.UserPrincipalName -eq "$SearchID"}) So why can it find the value in 2ms using "contains" method but takes more than 1000ms to read the actual record using the "where" method. Its as if it's using a different search algorithm in the "where" method. In fact it was faster to use Get-AdUser for each search as this only takes 900ms I've also tried other variations to no avail, such as: $AllADUsers | where-object {$_.UserPrincipalName -eq $SearchID} Any help gratefully received. Thanks blairkeiSolved2.1KViews0likes9CommentsConfigure AD FS 2016 and Azure MFA - How do I get the guid for Azure Multi-Factor Auth Client?
Hi All, I am trying toConfigure AD FS 2016 and Azure MFA as shown on the Microsoft site: https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/operations/configure-ad-fs-and-azure-mfa#step-1-generate-a-certificate-for-azure-mfa-on-each-ad-fs-server-using-the-new-adfsazuremfatenantcertificate-cmdlet It says "981f26a1-7f43-403b-a875-f8b09b8cd720 is the guid for Azure Multi-Factor Auth Client" but doesn't show how we get this GUID. When I try the command I get an error message I think is related to the GUID. How do I get theguid for Azure Multi-Factor Auth Client? I hope you can help ColinSolved9.2KViews0likes2Comments