Jump to content

fordea

Members
  • Posts

    70
  • Joined

  • Last visited

Everything posted by fordea

  1. You want to use $user.PrimaryCardID, not $_.PrimaryCardID. $_ in your ForEach-Object is referring to each item in the pipeline output by Get-ADGroupMember (which won't have the PrimaryCardID properties). Edit - Just realised it's only your PrimaryCardID null check where you've done this. Are you sure all of your users have a PrimaryCardID value because otherwise calling ToString() on it may return that error
  2. It's probably because your $Allgroup array has multiples of the same group name which is then causing errors when you are building the objects because each property name must be unique. Try to condense $Allgroup down after building it to only contain the unique group names: $Allgroup = $Allgroup | Select -Unique | Sort
  3. Sure, you can add a check in your foreach ($user in $results) loop that determines which user has the largest amount of groups: if ($groups.count -gt $maxgroups) {$maxgroups = $groups.count} and then at the end you can build a list of all the properties because you know what the largest number of groups was: $props = 'Username','Firstname','Surname' + (0..($maxGroups-1) | ForEach-Object {'Group{0}' -f $_}) $export = $Output | Sort-Object UserName | Select -Property $props $export | Out-GridView -PassThru | export-csv "d:\test\exuser.csv" -NoTypeInformation
  4. That should be straightforward to do, quick question - are you checking the Parent OU of the user for the IT Staff but checking if the user is in a security group for the HR staff?
  5. If you'd like to keep it in your format then you could feed all of the property names to Select-Objects property parameter which will then show them in the CSV even if the objects didn't contain said properties. You could build this property list by keeping track of the largest group number and then creating it at the end after looping through all the users.
  6. It depends really what you intend to do with the output. Is the output just for a human-readable report or is it something you want to feed in to another tool/cmdlet? Does it have to be in tabular format with all the different group names on each column?
  7. This is because you are creating an unspecified number of group properties for each $obj which may result in each one having a different amount of properties. When you try to output multiple objects with differing properties it will get those properties from the first object it sees and only show those for the rest of the objects. A simple example showing this: PS> $obj1 = [PSCustomobject]@{'group1'='test'} PS> $obj2 = [PSCustomobject]@{'group1'='test';'group2'='test2'} PS> $obj1,$obj2 group1 ------ test test PS> $obj2,$obj1 group1 group2 ------ ------ test test2 test Basically you need to know all of the groups that will appear in the objects upfront to display this correctly which isn't ideal.
  8. It sounds like you want to loop through each of the SQL instance Check data and then create an object for each with all the Name and Advice properties. I agree with HPlum78 that hashtables would be the way to go with this (+ the recommendation to check out Kevin Marquette's website as he has loads of great posts that I've learned a lot from). You could do something like this: foreach ($SqlInstance in $ScanResult.SecScan.SqlInstance) { $SqlInstanceData = [ordered]@{} $SqlInstanceData['Name'] = $SqlInstance.Name foreach ($Check in $SqlInstance.Check) { $sqlInstanceData[$Check.name] = $Check.Advice } [PSCustomObject]$SqlInstanceData } Having looked at the rest of your script I think you can consolidate it to something like this (although this doesn't have any excel formatting so you'd need to add that in): $CheckNameSortOrder = @( 'Security Updates', 'Automatic Updates', 'Incomplete Updates', 'Password Expiration', 'Windows Firewall', 'Local Account Password Test', 'File System', 'Autologon', 'Guest Account', 'Restrict Anonymous', 'Administrators', 'Auditing', 'Services', 'Shares', 'Windows Version', 'IIS Status', 'SQL Server/MSDE Status', 'IE Zones', 'IE Enhanced Security Configuration for Administrators', 'IE Enhanced Security Configuration for Non-Administrators', 'Macro Security' ) $SQLInstanceNameAbbr = @{ '(default)' = 'SQL' 'MSAS13.MSSQLSERVER' = 'MSAS13' 'MSRS13.MSSQLSERVER' = 'MSRS13' 'MSSQL13.MSSQLSERVER' = 'MSSQL13' '(default) (32-bit)' = 'SQL32' } foreach ($SecScan in $ScanResult.SecScan) { $Data = [ordered]@{} $Data['Server name'] = $SecScan.Machine foreach ($SecScanCheck in ($SecScan.Check | Sort {$CheckNameSortOrder.IndexOf($_.Name)})) { $Data[$SecScanCheck.Name] = $SecScanCheck.Advice } foreach ($SQLInstance in $SecScan.SQLInstance) { foreach ($SQLInstanceCheck in $SQLInstance.Check) { $Data["{0}_{1}" -f $SQLInstanceNameAbbr[$SQLInstance.Name], $SQLInstanceCheck.name] = $SQLInstanceCheck.Advice } } [PSCustomObject]$Data }
  9. What kind of output are you looking for - could you give an example maybe of how you want one of the lines from your post to look? It seems like you already have objects being output with a Name and Check property but I'm guessing you want it to be displayed differently?
  10. Are you sure the folder creation part works? It looks like you define the $NAS variable outside of the loop but then never change it when $Intake is defined or when $User changes within loop iterations. As $NAS is defined before $Intake or $User are defined its value will just stay at "\\truenas\MusicFiles\Script\Intake 20" throughout the script.
  11. According to the KQL docs: https://docs.microsoft.com/en-us/exchange/security-and-compliance/in-place-ediscovery/message-properties-and-search-operators you should be able to just specify 'from:constoso.com' to cover a whole domain.
  12. No need to manipulate the strings, just use the [Version] type accelerator as that will take care of the redundant zeroes: $LocalVersion = [Version](Get-Item "C:\Program Files (x86)\Teams Installer\Teams.exe").VersionInfo.FileVersion You can test it yourself by comparing the two examples you gave: $firstVersion = [Version][color=#333333]"1.3.00.28779" $secondVersion = [Version][/color][color=#333333]"1.3.0.28779" $firstVersion -eq $secondVersion[/color]
  13. -notlike should work, are you sure you're surrounding the OU name you want filtered with asterisks in Where-Object? You could also include a regex to make it more adaptable and exclude multiple sub-OUs if you need: $OUsToExclude = 'Service', 'Temp', 'Supply' $OUsToExcludeRegex = ($OUsToExclude | ForEach-Object {'(,OU={0},)' -f $_}) -join '|' And then you should be able to filter down the Get-ADUser results with a Where-Object: | Where {$_.DistinguishedName -notmatch $OUsToExcludeRegex}
  14. If you grab a list of the SIDs you want to skip you should be able to add a filter to Where-Object: $SIDsToSkip = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' | Select -ExpandProperty PSChildName Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore" | Where {$_.Name -like "*S-1-5-21*" -and $_.PSChildName -notin $SIDsToSkip}
  15. If a user is an owner in a team they won't be listed as a member because they can only be one of those roles
  16. You can do this in the teams admin center by altering your teams meeting policy that you apply to your teachers. The setting / value you need to change is: Roles that have presenter rights in meetings: Organizers, but users can override
  17. You can do this using meeting policies in the Teams Admin Centre. The option is under the participants & guests section and is called Automatically admit people. You would want to set that to Organizer only for the meeting policy that you apply to your teachers: https://docs.microsoft.com/en-us/microsoftteams/meeting-policies-in-teams#automatically-admit-people There's a handy Microsoft page that includes this information and more for setting up teams in an educational environment: https://support.microsoft.com/en-gb/office/keeping-students-safe-while-using-teams-for-distance-learning-f00fa399-0473-4d31-ab72-644c137e11c8?ui=en-US&rs=en-GB&ad=GB
  18. This should cover all four requests: #// Start of script #//List the groups you wish to exclude from csv output $groupsToExclude = @( 'TestGroup1', 'TestGroup2' ) #// Get year and month for csv export file $DateTime = Get-Date -f "yyyy-MM" #// Set CSV file name $CSVFile = "C:\directoryemails\adgroups"+$DateTime+".csv" #// Create emy array for CSV data $CSVOutput = @() #// Get all AD groups in the domain that have an email address and include their mail property. Exclude any groups defined at the top $ADGroups = Get-ADGroup -Filter "mail -like '*'" -properties mail | Where {$_.name -notin $groupsToExclude} #// Set progress bar variables $i=0 $tot = $ADGroups.count foreach ($ADGroup in $ADGroups) { #// Set up progress bar $i++ $status = "{0:N0}" -f ($i / $tot * 100) Write-Progress -Activity "Exporting AD Groups" -status "Processing Group $i of $tot : $status% Completed" -PercentComplete ($i / $tot * 100) #// Ensure Members variable is empty $Members = "" #// Get group members which are also groups and add to string $MembersArr = Get-ADGroup -filter {Name -eq $ADGroup.Name} | Get-ADGroupMember | select Name if ($MembersArr) { foreach ($Member in $MembersArr) { $Members = $Members + "," + $Member.Name } $Members = $Members.Substring(1,($Members.Length) -1) } #// Set up hash table and add values $HashTab = $NULL $HashTab = [ordered]@{ "Name" = $ADGroup.Name "Email" = 'mailto:{0}' -f $ADGroup.mail "Category" = $ADGroup.GroupCategory "Scope" = $ADGroup.GroupScope "Members" = $Members } #// Add hash table to CSV data array $CSVOutput += New-Object PSObject -Property $HashTab } #// Export to CSV files $CSVOutput | Sort-Object Name | Export-Csv $CSVFile -NoTypeInformation #// End of script You can change what groups to exclude from the csv at the top by adding / removing them from the $groupsToExclude array
  19. Sure you can add a Where-Object filter to check this and also change Get-ADUser to fetch multiple (or all) of your AD users. To check every AD User you could do: Get-ADUser -Filter * -Properties msDS-UserPasswordExpiryTimeComputed | Select Name, @{n='PwdExpiry';e={[Datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')}} | Where {[Datetime]::Now -gt $_.PwdExpiry} I'd recommend filtering Get-ADUser first to remove service accounts and the like if you only intend to check staff/pupil accounts.
  20. Try using the msDS-UserPasswordExpiryTimeComputed property: Get-ADUser j.bloggs -Properties msDS-UserPasswordExpiryTimeComputed | Select Name, @{n='PwdExpiry';e={[Datetime]::FromFileTime($_.'msDS-UserPasswordExpiryTimeComputed')}}
  21. You've added the hashPage.Add lines inside the tables loop but it needs to be outside. Should look like so: $hashPage.Add($tablecount,$arrTable) $tablecount++ } $hashPage.Add('FileName',$File) $hashPage.Add('Generated',$dateGenerated) $objPage = New-object -TypeName PSCustomObject -Property $hashPage Return $objPage }
  22. So a quick kludgy way of getting your desired output is to grab the generated value from the HTML center tag (because its the only center tag in your sample HTML) and then add both the Filename and Generated values as properties of the Get-HTMLTables output. Add the following near the top of the Get-HTMLTables function: $dateGenerated = (($html.all.tags("Center") | Select -ExpandProperty innertext) -split ',')[0] Then add both the Filename and dateGenerated variables to the hashPage so that they're output by the function. Put these just before the end of the function before $objPage is created and returned: $hashPage.Add('FileName',$File) $hashPage.Add('Generated',$dateGenerated) Then it's just a matter of filtering your results again but this time Selecting the Filename, Generated and any other properties you want. So for example to output the FileName, Generated Date, Server and Status: ($results.0).Where{$_.Server -match 'Server1' -and $_.Status -eq 'Online'} | Select @{n='FileName';e={$results.FileName}}, @{n='Generated';e={$results.Generated}}, Server, Status
  23. Is every input file in the same format? I.e one table row and then the date/time it was generated at the bottom?
  24. Are you just trying to output the list of filenames that hit a match with your Where-Object filter into a single txt file or do you need any rows from the input files that match the filter to also be output into that txt file?
  25. I think you missed changing the $tables line in the function. If you change the $tables assignment in the function to the following it should work $tables = $html.all.tags("table")
×
×
  • Create New...