Reply To: Help Simplifying Code
Why don’t we go completely crazy and access the IEnumerable.Where() function instead? $students = @(Import-Csv 'C:\StuGroups\Students.csv').Where({ $_.grade_code -NotIn 'KG','1','2' })
View ArticleReply To: One Config, Many Nodes — Best Practices?
Thank you for the comments, I am using Pull mode, and after looking at the MOF generated some more, I’m hoping I have a better understanding but please correct me if I’m wrong. I didn’t see these...
View ArticleReply To: Help Simplifying Code
That only works on PowerShell 4.0 or later. Strictly speaking, it’s not the .NET IEnumerable.Where() method, though the syntax does look similar.
View ArticleReply To: One Config, Many Nodes — Best Practices?
When you’re using a pull server, the node in your configuration is the GUID that you’re using as the ConfigurationID on the target node(s). Hostnames never enter the picture.
View ArticleReply To: One Config, Many Nodes — Best Practices?
Ok, that makes sense. Thank you very much Dave. Initially I was thinking that the final MOF file was going to contain the node name which is why I thought I might have to use localhost so that it...
View ArticleConfused about -or behavior in an If/Then construct
EDIT: Disregard this. My fault. $a = $null if (!$a or (Test-Path 'C:\Windows')) { } Given this simple scenario, in what instances would Powershell evaluate the (Test-Path ‘C:\Windows’) condition? It...
View ArticleConditional formatting in psobject output
Is there an elegant way to conditionally format psobject output to the console? I wrote a script to check if a specific service is running or stopped on a number of computers, and used IF logic and...
View ArticleReply To: One Config, Many Nodes — Best Practices?
I think you may have been overthinking it a little, is all :). But yes, the key thing is that the MOF doesn’t include a host name. Using the host name as the MOF filename is solely for the benefit of...
View ArticleReply To: Conditional formatting in psobject output
No. The formatting system is more or less color-blind, because it needs to work with more than just the console host. If you’re okay with limiting yourself to the console for output, and you’ve named...
View ArticleReply To: Conditional formatting in psobject output
Understood. I’ll check out the EnhancedHTML module and look into integrating HTML output into my workflow.
View ArticleReply To: Help Simplifying Code
I kind of just assumed the PowerShell guys had half-way implemented some kind of not-quite-LINQ functionality, and I was sort of dreaming that they’d keep working on it and do the whole PowerShell...
View ArticleReply To: Help Simplifying Code
If you’re not careful you can find yourself spending an hour trying to squeeze another 100ms out of a script that might only run 10 times in production before it’s obsolete.
View Articlelooking for guidance regarding html reporting
please excuse my lack of knowledge. im looking for some guidance. I have numerous scripts I have made that do one thing or another.. ive gotten some great knowledge re; powershell and now im looking...
View ArticleRunning PSexec from powershell
Here is the code I have: forEach ($computer in $computers) { if (!(test-Connection -Cn $computer -quiet)) { psexec.exe “\\”%$computer% net localgroup users’ } else { Write-Host $computer is not online...
View ArticleReply To: Running PSexec from powershell
You can use Get-Content to read a text file’s contents into a variable – like $computers.
View ArticleReply To: looking for guidance regarding html reporting
What is it exactly you’re looking to make possible? Writing to a CSV file? Generating a custom object? I’m confused about what the question is, sorry.
View ArticleReply To: Help Simplifying Code
I had a “duh” moment. The student file had building codes in it and it so happens that KG through 3rd Grade are house in a particular building. So this worked out just fine. Import-Csv...
View ArticleRuns fine in the ISE but not when ran as a script?
$date = Get-Date -Format MM.d.yyyy $OutputDir = “C:\Reports\SQL” $File = “Sql_” + “$date” + “.csv” $OutputFile = Join-Path $OutputDir $file if(!(Test-Path -Path $OutputDir)) {mkdir $OutputDir} else...
View ArticleReply To: Help Simplifying Code
You can use array slicing on the string $loginName = ($lastNameFiltered + “.” + $firstNameFiltered)[0..19] -join '' That will produce the same result, but doesn’t fuss if the string is less than 20...
View ArticleReply To: Runs fine in the ISE but not when ran as a script?
When ran a portion at a time everything executes perfectly! when ran all at once i get nothing no error no out at all
View Article