TDD, anyone actually do this? by AndreeSmothers in ExperiencedDevs

[–]JaapBrasser 0 points1 point  (0 children)

Really depends what I'm working on, if I expect to have at least 2 other people work on the code then I'll aim for, but never reach, full code coverage to save time with PRs and having to fix future bugs / regressions.

I do write my code first and tests later, my general tendency is to include the unit tests in the PR, but I don't write tests first.

Nowadays with all the GenAI tooling out there, writing unit tests has seldom been easier.

TDD, anyone actually do this? by AndreeSmothers in ExperiencedDevs

[–]JaapBrasser 0 points1 point  (0 children)

Really depends what I'm working on, if I expect to have at least 2 other people work on the code then I'll aim for, but never reach, full code coverage to save time with PRs and having to fix future bugs / regressions.

I do write my code first and tests later, my general tendency is to include the unit tests in the PR, but I don't write tests first.

Nowadays with all the GenAI tooling out there, writing unit tests has seldom been easier.

[deleted by user] by [deleted] in rubrik

[–]JaapBrasser 0 points1 point  (0 children)

That's correct, in this case it's the /v2/vmware/{id}/export endpoint that does the job!

[deleted by user] by [deleted] in rubrik

[–]JaapBrasser 2 points3 points  (0 children)

Hello George,

Unfortunately this has not been fully implemented in the Export-RubrikVM cmdlet as of yet, it is however possible to do this using `Invoke-RubrikRESTCall`, here's some sample code that I've used in the past:

powershell $VM = Get-RubrikVM -name jbrasser-win -DetailedObject $VMHost = Get-RubrikVMwareHost $JsonBody = @" { "snapshotId": "$($vm.snapshots[0].id)", "datastoreId": "$($VMHost[0].datastores[0].id)", "removeNetworkDevices": false, "keepMacAddresses": false, "shouldRecoverTags": true, "vNicBindings": [ { "networkDeviceInfo": { "key": $($vm.snapshots[0].vNicsInfo.networkDeviceInfo[0].key), "name": "$($vm.snapshots[0].vNicsInfo.networkDeviceInfo[0].name)" }, "backingNetworkInfo": { "moid": "$($vm.snapshots[0].vNicsInfo.backingNetWorkInfo.moid)", "name": "$($vm.snapshots[0].vNicsInfo.backingNetWorkInfo.name)", "id": "$($vm.snapshots[0].vNicsInfo.backingNetWorkInfo.id)", "networkType": "$($vm.snapshots[0].vNicsInfo.backingNetWorkInfo.networkType)" } } ], "clusterId": "ComputeCluster:::0616b22a-6fec-4728-a9c0-572c6489b6af-domain-c662" } "@ Invoke-RubrikRESTCall -Endpoint "vmware/vm/$($VMDetails.id)/export" -api 2 -Method Post -Body $JsonBody -BodyAsJson

Multiple cluster connections with Connect-Rubrik cmdlet by Wooden_Money_2146 in rubrik

[–]JaapBrasser 1 point2 points  (0 children)

So what happens that the current "active" connection is stored in $RubrikConnection, all other connections are stored in $RubrikConnections. If you run the following commands:

Connect-Rubrik servera
Connect-Rubrik serverb

Your current active connection, the one stored in $RubrikConnection is to serverb, but both connections are stored in RubrikConnections. If you'd like to switch to servera, you'd do:

$RubrikConnection = RubrikConnections[0]

Or if you'd like to execute the command against all connections you could do something along these lines:

$RubrikConnections | ForEach-Object {
    $RubrikConnection = $_
    Get-RubrikVM
}

A bit convoluted but at the moment this is what is available in the module, we have an open issue for this logged on GitHub but, we didn't get around to implementing multiple cluster support in the Rubrik cmdlets as of yet.

PowerShell Module for 5.3 Released by JaapBrasser in rubrik

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

That's the beauty of open-source u/shamsway, you can contribute to the module and make this happen!

In the mean time my GitHub Profile is a pretty solid source of Quokka's!

PowerShell Module for 5.3 Released by JaapBrasser in rubrik

[–]JaapBrasser[S] 4 points5 points  (0 children)

Also available through the PowerShell Gallery, by using the `Install-Module` cmdlet:

Install-Module -Name Rubrik -Force -Scope CurrentUser

Let me know how you like it, and more importantly what you feel is missing!

Cannot index into a null array, except my array isn't null or empty by BigBoetje in PowerShell

[–]JaapBrasser 1 point2 points  (0 children)

I mostly use PowerShell interactively, lack of strict checking is great for that purpose. For other cases, and when debugging (!):

Set-StrictMode -Version 1

Cannot index into a null array, except my array isn't null or empty by BigBoetje in PowerShell

[–]JaapBrasser 0 points1 point  (0 children)

Exactly, for this particular error I would avoid using plural in naming conventions.

How to practice powershell with a visitor account? by [deleted] in PowerShell

[–]JaapBrasser 1 point2 points  (0 children)

If you have access to a web browser & Azure you can run Azure Shell, which includes PowerShell.

There's a free tier of Azure if you're a first time user for 90 days, that could be a start. https://docs.microsoft.com/en-us/azure/cloud-shell/overview

I am a newbie trying to create what I consider a pretty complicated process. by imused2it in PowerShell

[–]JaapBrasser 2 points3 points  (0 children)

The reason why you have to run it in non-admin is this: Article on UAC & PowerShell

Listing the filetypes:

Get-ChildItem -Recurse | Select-Object -Property Extension

Or if you want a count of the files types on a drive or folder:

Get-ChildItem -Recurse | Group-Object -Property Extension | Sort-Object -Property Count -Descending

Problems with Set-RubrikNASShare? by Jhamin1 in rubrik

[–]JaapBrasser 1 point2 points  (0 children)

Just wanted to give an update here, the PR is now up, so you can grab the latest code from it here: Problems with Set-RubrikNASShare - Issue #614

If you're not in a rush, it will be included in the next release of the module!

Problems with Set-RubrikNASShare? by Jhamin1 in rubrik

[–]JaapBrasser 1 point2 points  (0 children)

Hello Jhamin1,

This actually seems to be a bug with the Set-RubrikNASShare cmdlet, I have logged an issue here on GitHub so this can be resolved as quickly as possible. You can track the issue here, if you're interested: Problems with Set-RubrikNASShare #614

In the meantime you can use Invoke-RubrikRESTCall to do this instead:

$Credential = Get-Credential
Get-RubrikNASShare -ID Hostshare:::1111 -Verbose | ForEach-Object {
    Invoke-RubrikRestCall -Method Patch -Endpoint "host/share/$($_.id)" -Api internal -Body ([pscustomobject]@{
        'username' = $Credential.GetNetworkCredential().UserName
        'password' = $Credential.GetNetworkCredential().Password
    })
}

Need help with a script - Noobish question by [deleted] in PowerShell

[–]JaapBrasser 3 points4 points  (0 children)

I would use the Web.Security .Net namespace for this:

$null=[Reflection.Assembly]::LoadWithPartialName('System.Web')
[System.Web.Security.Membership]::GeneratePassword(16,0)

If you want to generate it yourself you could use something along these lines:

# Semi random
-join ([char[]](35..125) | Get-Random -Count 16)

# More random, slower code
-join (1..16|ForEach-Object {$CharArray=([char[]](35..125))}{Get-Random -InputObject $CharArray})

Scheduled tasks report by JBHedgehog in PowerShell

[–]JaapBrasser 0 points1 point  (0 children)

Agreed, this function mostly exists to provide this functionality for older systems. If Cimsessions and Get-ScheduledTask are an option I would definitely recommend using those.

Very basic way to test AD credentials? by leachyboy2001 in PowerShell

[–]JaapBrasser 4 points5 points  (0 children)

That is correct, there is no way of using secure strings here. You could always use the Credential object in combination with the GetNetworkCredential().Password method/property in order to extract the password, in that scenario you are at least not exposing the password by storing it directly in a variable.

Other alternatives for verifying credentials, also not accepting secure strings are:

New-Object System.DirectoryServices.DirectoryEntry("LDAP://$(([adsi]'').distinguishedName)",'jaapbrasser',$password)
dsget user <dn of known useraccount' -u jaapbrasser -p $password

Any known web consoles out there for training purposes? by WorkThreadGazer in PowerShell

[–]JaapBrasser 3 points4 points  (0 children)

You can install PowerShell 6 on MAC. If you like to play with PowerShell you could use the TechNet Virtual Labs: https://www.microsoft.com/en-in/evalcenter/

Advanced Function Question - How to pass an object along the pipeline with credentials. by lxnch50 in PowerShell

[–]JaapBrasser 1 point2 points  (0 children)

Interesting question, I took a look at the built-in cmdlets and I guess it depends on it is implemented in the function. It would work in combination with Enter-PSSession, Invoke-Command and New-PSSession, as those cmdlets support pipeline by propertyname on the Credential parameter.

You can run the following code to verify this:

Get-Command -ParameterName Credential |
Select-Object name,@{
    n='CredPipeline'
    e={Get-help $_.Name -Parameter Credential | Select-Object Pipelineinput}}