Jump to content

fordea

Members
  • Posts

    70
  • Joined

  • Last visited

Reputation

200 Excellent

1 Follower

About 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
×
×
  • Create New...