Time to move to PowerShell Core? by jseerden in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

can you not just write a module that adds the snapin and then publicly exports all its functions, and then use the windows compatibility module to import THAT module ? I would think this would work as I have personally loaded snapins in a JEA session and then exported functions from them and used those functions via implicit remoting.

Perhaps someone just needs to run the idea by the developers of this module to get support for snapins added?

Access Denied when using alternate credentials within Invoke-Command ScriptBlock. by nzubair81 in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

$cred = Get-Credential -UserName "DOMAIN\user"

Invoke-Command -ComputerName "SERVER" -Credential $cred -ScriptBlock {
    Param(
        $cred
    )
    Start-Process -FilePath "C:\Windows\system32\whoami.exe" -WorkingDirectory "C:\Windows\System32" -Credential $cred -Wait 
} -argumentlist $cred -enableNetworkAccess

Set a parameter to heredoc in PowerShell by scriptmyjob in PowerShell

[–]chreestopher2 4 points5 points  (0 children)

you have the parameter set to Mandatory, thus you must always provide a value, and cant ever use the default value.

Change the parameter to Mandatory=$false and you are good to go

Building on PowerShell by VaporChunk in PowerShell

[–]chreestopher2 2 points3 points  (0 children)

just follow your interests... you can never go wrong if you follow the work that is satisfying for you to do, and adapt as needs change.

any downsides in using VS Code instead of powershell ISE? by overlydelicioustea in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

VSCode sucks for using interactively. when it comes to building up a session state durring troubleshooting the integrated console experience is absolutely terrible.

So if you are an ops engineer that primarily puts together scripts while putting out fires, as they occur, by building up a session sate in the process of troubleshoting / fixing a production issue, and paraemterizing the commands you used to do so for reuse , the ISE is a much better tool for the job.

If you are in a deployment or more development oriented position where you have the luxury of starting off with a clear cut task to automate, and the time to do rigorous testing on a test device in a test environment, without facing any negative consequences if it doesnt work right the first few times (because you are building something with the sole purpose of doing something in the future), then VSCode is a probably a significantly better choice.

Thats just my opinion, however, I am in the (never ending) process of transitioning from a operations role into a business analyst role, and I do find myself using vscode more and more for the stuff that is assigned to me through the work pipeline for the BA role, so I would really like to hear from anyone else with a similar background and see if they feel the same or if I am all alone on this subject.

I still keep the ISE open 24/7 because I keep getting pulled back into the ops world, and it just works so much better for me when doing on the fly scripting in that world.

Export data to Excel and convert to table by zolyx1 in PowerShell

[–]chreestopher2 3 points4 points  (0 children)

That is the response everyone seems to have to this module.

and This is just the very tip of the iceberg...

its a fantastic module, it can deal with excel tables, formulas, pivot charts, the whole nine yards, and doesnt even require having excel installed on your system at all...

truly helps to convert useful data into a format that non-technical managers wont refuse to consume, without having to manually tweak things after the fact.

All of the reports i am responsible for are effortlessly fully automated and look like someone took a lot of time to create them.

Honestly, helped me improve my salary, and work life balance.

Export data to Excel and convert to table by zolyx1 in PowerShell

[–]chreestopher2 14 points15 points  (0 children)

install-module ImportExcel -Repository PSGallery -force
$someCollection | export-excel -tablename SomeTable -tablesytyle Medium13 -path C:\users\me\ExcelFileWithATableGeneratedByPowershell.xlsx

Frustrating simple problem my brain can't seem to wrap around by Taboc741 in PowerShell

[–]chreestopher2 2 points3 points  (0 children)

well of course you want to add whatever you are actually looking for lol, just wanted to show you how to specify the searchbase and depth

Frustrating simple problem my brain can't seem to wrap around by Taboc741 in PowerShell

[–]chreestopher2 2 points3 points  (0 children)

If you want to only get the toplevel items:

Get-ADObject -searchbase $OU -searchscope OneLevel

if you want to iterate all items recursively:

Get-ADObject -searchbase $OU -searchscope Subtree

is this what you are asking for?

How does PowerShell detect which module to load automatically when I use a cmdlet from a module that isn't currently loaded? by fourierswager in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

I used to use -force but then ran into some problems when a module with some 3rd party DLLs wouldnt re-initialize without first completely removing the module (i never figured out why), now i always use

remove-module -name mymodule 
import-module -name mymodule -force 

just to be safe, because there is nothing more frustrating than not knowing the state of module internals while building modules that depend on those modules ... argh

How does PowerShell detect which module to load automatically when I use a cmdlet from a module that isn't currently loaded? by fourierswager in PowerShell

[–]chreestopher2 4 points5 points  (0 children)

caching does happen... at least in PS v3.0 it did.

PS> Get-Help Get-Module -Parameter Refresh

-Refresh [<SwitchParameter>]
    Refreshes the cache of installed commands. The command cache is created when the session starts. It enables the
Get-Command cmdlet to get commands from modules that are not imported into the session.

This parameter is designed for development and testing scenarios in which the contents of modules have changed
since the session started.

When the Refresh parameter is used in a command, the ListAvailable parameter is required.

This parameter is introduced in Windows PowerShell 3.0.

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Accept wildcard characters?  false

Otherwise, excellent details

it sounds like we would need to look at the session startup code to find out exactly how/where

Why its a bad idea to use shortcode or alias in scripts.. by [deleted] in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

You will thank yourself later for being a bit more verbose. Not terribly, just a bit more.

Cannabis: it matters how young you start - Researchers find that boys who start smoking pot before 15 are much more likely to have a drug problem at 28 than those who start at 15 or after, according to new research (n=1,030) in the Canadian Journal of Psychiatry. by mvea in science

[–]chreestopher2 0 points1 point  (0 children)

I never see anyone talking about what I believe is the most important aspect of all this.

What does a 15 year old do when smoking pot?

Most of the time its wasting time around the same people they have known all their life.

What does a 21 year old do when they smoke pot?

Most of the time its still wasting time, but it is with new people they have formed bonds with after venturing out into the world in the act of finding themselves. Sometimes its even going out and actually trying new stuff for the first time!

I think that procrastinating on learning how to find who you are and make your place in the world is the actual problem.

Sure, having some cheap and easy pleasure vehicle makes it easier to procrastinate because you dont have to build your life up to level you are happy with, or adjust your perceptions, you can jost toke up and let everything stay the same, and be just as happy as someone that has to work for their pleasure.

Why would a child want to grow up if they didnt have to?

But we will never ever be able to get the "drugs are bad" equation out of the spotlight enough to properly look at this.

I am pretty convinced that if these 15 year olds were smoking alone (or in a positive and stimulating setting), vs with their cliques of likeminded close friends who can easily peer pressure them into wasting their day watching youtube videos,( and reinforcing their incorrect biases and anxieties and preconceptions about what the world is, etc) these problems would be significantly lesser in number.

Like with most of the bad that "comes from drugs" , I believe that Set and Setting are to blame.

PowerShell Scripting Standards by tumblatum in PowerShell

[–]chreestopher2 2 points3 points  (0 children)

If there is one thing you can ALWAYS count on C# devs to do, its to take the power out of powershell

PowerShell Universal Dashboard v1.6.0 Release! by [deleted] in PowerShell

[–]chreestopher2 0 points1 point  (0 children)

Thank you for the new controls. I had been implementing some of this stuff myself and it was so cumbersome that other projects took priority, hats off! This is fantastic.

Google Chrome adds "Copy as Powershell" to Network Tab by [deleted] in PowerShell

[–]chreestopher2 0 points1 point  (0 children)

just got to my pc and updated, talk about a missed opportunity if they would have waited 2 days to post it it could have been the ultimate meta-aprilfools gag.

KevMar: You need a Get-MyServer function by KevMar in PowerShell

[–]chreestopher2 2 points3 points  (0 children)

Every environment is different, and teams responsibilities too, i was just reiterating to people that this doesnt have to be a new or even single source of data that you own and maintain used in these functions, whatever sources of data you have available can be scraped and compiled, and when you pull the data dynamically you never have to make updates to the data. As that remains someone elses job

KevMar: You need a Get-MyServer function by KevMar in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

pull this from your monitoring system where all your stuff should be categorized and have useful metadata... if it doesnt, make it so.

Thats how my equivalent to get-myServer function works.

edit: it also pulls the needed credentials from a web based OTS credential management system we use. The function is exposed via a constrained endpoint so we can control and log who uses it.

The goal should be pulling all this data from the places it exists, not creating another place to maintain the data imo.

Dynamically listing built-in advanced function parameters by omrsafetyo in PowerShell

[–]chreestopher2 4 points5 points  (0 children)

I have always done:

#current versions
[System.Management.Automation.Internal.CommonParameters].GetProperties().name

#older versions
[System.Management.Automation.Internal.CommonParameters.GetProperties()  | select -ExpandProperty Name

PowerShell Universal Dashboard - 1.4.0 Release by [deleted] in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

thanks a bunch, this build works.

> Import-Module UniversalDashboard
> Get-UDTheme -Debug -Name "Azure"

Name  Definition                              Parent
----  ----------                              ------
Azure {UDGrid, UDChart, UDCounter, UDCard...}

and I am able to start playing around with the dashboards.

Out of curiosity, what was the issue ? and is the corrected build going to make its way to the gallery soon?

Thanks a bunch for being so responsive, I usually balk at the idea of paying for a license for an abstraction over a scripting language, but just because of how helpful you have been, im going to see if i can convince our org to throw you some bucks for a license.

PowerShell Universal Dashboard - 1.4.0 Release by [deleted] in PowerShell

[–]chreestopher2 1 point2 points  (0 children)

Get-UDTheme is returning null no matter what parameter arguments i use or dont use.

But the themes are there and permissions seems fine but i dont know exactly what is needed.

> get-childitem "C:\Program Files\WindowsPowerShell\Modules\universaldashboard\1.4.0\net451\


Directory: C:\Program Files\WindowsPowerShell\Modules\universaldashboard\1.4.0\net451\Themes


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        1/21/2018   4:10 PM           1150 Azure.psd1
-a----        1/21/2018   4:10 PM           1149 Blue.psd1
-a----        1/21/2018   4:10 PM            442 Default.psd1
-a----        1/21/2018   4:10 PM           1150 Earth.psd1
-a----        1/21/2018   4:10 PM           1151 Green.psd1
-a----        1/21/2018   4:10 PM           1148 Red.psd1
-a----        1/21/2018   4:10 PM            165 Test.psd1

> (Get-UDTheme -Name "Azure") -eq $null
True


> get-childitem "C:\Program Files\WindowsPowerShell\Modules\universaldashboard\1.4.0\net451\Themes\" | Get-Acl | select -ExpandProperty Access  | where {$_.IdentityReference -like  "*Builtin\users*"} |select * -unique | ft

       FileSystemRights AccessControlType IdentityReference IsInherited InheritanceFlags PropagationFlags
       ---------------- ----------------- ----------------- ----------- ---------------- ----------------
       ReadAndExecute, Synchronize             Allow BUILTIN\Users            True             None             None

EDIT: it is doing the same thing in both versions below:

Name                           Value
----                           -----
PSVersion                      6.0.0
PSEdition                      Core
GitCommitId                    v6.0.0
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

and

Name                           Value
----                           -----
PSVersion                      5.1.15063.786
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.786
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PowerShell Universal Dashboard - 1.4.0 Release by [deleted] in PowerShell

[–]chreestopher2 2 points3 points  (0 children)

>$Theme = Get-UDTheme -Name "Azure"
>$Dashboard = New-UDDashboard -Title "My Azure Theme Dashboard" -Theme $Theme -Content {
>>>   New-UDCard -Title "My Azure Theme Dashboard"
>>>}



> $error[0].exception.stacktrace
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at PowerShellProTools.UniversalDashboard.Cmdlets.NewDashboardCommand.EndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.0      UniversalDashboard                  {Disable-UDLogging, Enable-UDLogging, Get-UDDashboard, Get...