• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

Whats wrong with my script?

For some reason my script does not output any data. Can someone figure out what I'm missing?

 
%{get-qaduser -notes * -includedproperties ExtensionAttribute5 -sizelimit 0 |  Select-Object `  
  @{n='SamAccountName';e={ $_.samaccountname }},  
  @{n='Account Status';e={if($_.AccountIsDisabled){"Disabled"} Else {"Enabled"} }},  
  @{n='SBG';e={ $_.extensionAttribute5 }},  
  @{n='Has Notes?';e={ $_.Notes }},
  @{n='DN';e={ $_.DN }}  
  
  } | export-csv "G:\Scripts\UsersWNotes\Profiles.csv" -notypeinformation

Open in new window


When i Run the above code it does create the csv file and I can see it building in size. When it completes i open and its blank.
0
ntr2def
Asked:
ntr2def
1 Solution
 
LearnctxEngineerCommented:
Unless it was done by the website, there seems to be some formatting issues with your script. On the first line:
%{get-qaduser -notes * -includedproperties ExtensionAttribute5 -sizelimit 0 |  Select-Object `\s\s

Open in new window

If you remove the 2 spaces at the end it runs fine. After doing that and copying your script as is, it outputs fine. The \s is just there to indicate where the spaces are. So for this works fine.
%{ get-qaduser -notes * -includedproperties ExtensionAttribute5 -sizelimit 0 |  Select-Object `
  @{n='SamAccountName';e={ $_.samaccountname }},  
  @{n='Account Status';e={if($_.AccountIsDisabled){"Disabled"} Else {"Enabled"} }},  
  @{n='SBG';e={ $_.extensionAttribute5 }},  
  @{n='Has Notes?';e={ $_.Notes }},
  @{n='DN';e={ $_.DN }}  
} | export-csv $env:TEMP\test.csv -notypeinformation

Open in new window

0
 
Chris DentPowerShell DeveloperCommented:
You can drop that opening ForEach-Object loop (%{ ... }), you really don't need it. And you don't need to rewrite the field names unless you're changing things.
Get-QADUser -Notes * -IncludedProperties ExtensionAttribute5 -SizeLimit 0 |  Select-Object `
    SamAccountName,  
    @{n='Account Status';e={ if ($_.AccountIsDisabled) { "Disabled" } Else { "Enabled" } }},  
    @{n='SBG';e={ $_.extensionAttribute5 }},  
    @{n='Has Notes?';e={ $_.Notes }},
    DN | 
  Export-Csv $env:TEMP\test.csv -notypeinformation

Open in new window

Unnecessary code upsets me you see :)

Chris
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now