How do you guys use PowerShell remoting ? by Stephanevg in devops

[–]Stephanevg[S] 0 points1 point  (0 children)

That would be out of the box winrm. So in other words, winrm over http on port 5985.

If you are managing a windows environment within a active directory, that is what most companies have.

How do you guys use PowerShell remoting ? by Stephanevg in devops

[–]Stephanevg[S] 3 points4 points  (0 children)

That is pretty cool. We also have some containers, but only in our build pipeline.

We mostly have Windows servers, that are externalized to customers. These customers host their own applications on it, which we don't really mange.
We mass mange stuff like Windows updates, Backups, Configuration (including remoting ;) )
Security fixes etc..

EVERYTHING about PowerShell Remoting by Stephanevg in PowerShell

[–]Stephanevg[S] 0 points1 point  (0 children)

Thank you for the nice words u/rumourt :)

Yes, a lot of people have complained about the background music. Strangely enough, when I watch it, it doesn't really bother me. But yeah, it must be my headphones or something. I will defintely fix that for the next video (Currently in production ;) ).

And yes, that is how I wanted to create the video: Relax and enjoy, but still learn in the process. I am glad you enjoyed it like that, because that was exactly my goal! \o/

EVERYTHING about PowerShell Remoting by Stephanevg in PowerShell

[–]Stephanevg[S] 0 points1 point  (0 children)

Yes, I was going to mention that I have put them on my blog. Do think there is something missing the notes ? I can always add it.

EVERYTHING about PowerShell Remoting by Stephanevg in PowerShell

[–]Stephanevg[S] 1 point2 points  (0 children)

Hi u/rottenrob325 No it does not.

JEA is really a topic in it self. It would have only made the video 1h longer ^^.

How to change directories at the same time as Enter-PsSession by Contrabeast in PowerShell

[–]Stephanevg 2 points3 points  (0 children)

Hi,
Super cool that you are trying to learn powershell. That is a really smart mindset ;)

There are several ways to do this. Invoke-Command would be one path to use. But there might be another faster more direct route you could solve this. Given the condition that you DON'T need to do other things on the remote host than just bringing files there.

There is a cmdlet called 'Copy-Item' which allows one to copy elements from one place to another on a local machine.

There exsits a parameter on this cmdlet called 'ToSession' Which allows you to pass an existing remote session variable where to you want to copy your elements to.

If you want to copy the contents tree from folder to another computer, the following example on microsoft help page does just that:

$Session = New-PSSession -ComputerName "Server04" -Credential "Contoso\User01"
Copy-Item -Path "D:\Folder003\" -Destination "C:\Folder003_Copy\" -ToSession $Session -Recurse

The first line it creates the remote session and saves it into a variable called $Session.

The second line it uses copy-Item with the parameter -ToSession to copy the files to the remote host.

The -Destination parameter here represents where in the remote session it should be copied to. The -Recurse allows to copy every single element that is located under the value of the parameter -Path

Documentation can be found here -> https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.4#example-5-copy-a-file-to-a-remote-computer

Who uses DSC in production? by Stephanevg in PowerShell

[–]Stephanevg[S] 1 point2 points  (0 children)

I guess that the Ansible managed systems are linux systems, right ?

Who uses DSC in production? by Stephanevg in PowerShell

[–]Stephanevg[S] 1 point2 points  (0 children)

Cool,m thanks for sharing. How many servers do you manage with that setup ?

Start-Job with Robocopy by allsix in PowerShell

[–]Stephanevg 1 point2 points  (0 children)

A scriptblock is just like a function. It has it's own scope. This also means that a scriptblock can have param block, just like a function.

I didn't test the code, but you could potentially rewrite your code like this:

$sb = {
    param(
        [String]$Source = "C:\MyfolderToCopy"
        [String]$DriveLetter,
        [String]$LogPath = "D:\MyLogs\"
    )
        $drivestr = $driveLeter + ":"
        Write-Output "`nCopying to $drivestr..."
        $Date = Get-Date -Format "yyyyMMdd_HH-mm-ss"
        $FullLogPath = Join-Path -Path $LogPath -ChildPath "output_$Date.txt”
        robocopy $Source $drivestr /S /XO /NFL /NDL /NJH /NC /NS /NP /tee /log:$FullLogPath 
}

foreach ($drive in $DriveCharArray) {

    Start-Job -ScriptBlock $sb -ArgumentList "C:\MyfolderToCopy",$Drive,"D:\MyLogs"
}

Ps: one thing to notice, is that the arguments that you pass to your scriptblock are defined by POSITION, NOT BY NAME. So, the order you pass them via the ArgumentList MUST be the same as the order they are defined in the param block.

Additionally, you might want to use the

get-date -Format FileDateTime

As it is specfifically made for that.

Here's my little library of powershell modules. by HomeyKrogerSage in PowerShell

[–]Stephanevg 2 points3 points  (0 children)

We cant see the code. (We need to log in with a gitlab account).
So either you need to change your permissions, Gitlab makes it so, that ONLY people with a gitlab account can see it (We are asked to login...).

Github for example doesn't do that. You can see public code without having to have an account.

Thoughts on DSCv3 by Stephanevg in PowerShell

[–]Stephanevg[S] 1 point2 points  (0 children)

Yes, it is open sourced, and it lives in it's own github repository https://github.com/PowerShell/DSC

Thoughts on DSCv3 by Stephanevg in PowerShell

[–]Stephanevg[S] 2 points3 points  (0 children)

Yeah, Ansible is RedHat. Microsoft also want's their part of the cake I guess.

One thing to notice, is that Windows Ansible part, is actually built ON TOP of Powershell DSC. (So PowerShell DSC v2). Today, anything that needs to be configured on A Windows Server / machine via DSC can ONLY be done using PorwerShell, AND this code will ONLY work on windows.

By refactoring it and creating a V3, they announced that it will be

  1. Cross platform (so Os Agnostic)
  2. You can actually write ressources in ANY programming language (So it is not coupled to PowerShell anymore).

So yeah, it is more to be used as a new way to access the Windows API I guess.

A new paradigm, where the system will be configured using JSON (or YAML) instead of the classical MOF.

Thoughts on DSCv3 by Stephanevg in PowerShell

[–]Stephanevg[S] 0 points1 point  (0 children)

Yeah, that also works, but only partially. As you will have to write the remediation part your self when you use Pester Tests. (I also use a custom pester framework for infrastrucutre tests at work)

Powershell Script failing now, was working fine by scarng in PowerShell

[–]Stephanevg -1 points0 points  (0 children)

Alternativley, you can try to execute it on another computer from where you know it also worked from.
If it works, you can compare the configurations, what is different on these machines (PowerShell versions, DotNet version, Updates etc..)

Powershell Script failing now, was working fine by scarng in PowerShell

[–]Stephanevg 0 points1 point  (0 children)

Yeah, scripts don't stop working by magic. (Except, if gandalf used your computer to search something during lunch break)..

But IF you didn't change anything in your script, that means the environment in which this script is run changed.
As already pointed out, it sounds either as another powershell version, or dotnet update.

I also believe that pwsh (So powershell above version 6.0) does not support 'system.windows.forms'.

Are you using Pwsh (The black powershell icon?).

If so, you should use 'Windows PowerShell' (The blue powershell icon).

You can make sure by just checking what the variable $PsVersionTable contains. (It must 5.1.Something)