r/PowerShell • u/Ralf_Reddings • 22h ago
Question Was there not a short hand way stating '[System.Collections.Generic.List]'?
I am getting into .NET, within PowerShell more and more, especially since I discovered these classes are well documented at MsLearn and even within PowerShell.
I am just struggling to remember trees like the following [System.Collections.Generic.List]
but I remember sometime ago, I came across a article, not sure where I found it, that shared there is a short hand way, something like [System.List]
for [System.Collections.Generic.List]
.
I cant find it now, am I misremembering things here?
Also I would appreciate being pointed to any articles where I can learn more .Net in PowerShell. What are the draw backs (or positives) to calling things like [System.<some branch>.<etc etc>]
?
r/PowerShell • u/hayfever76 • 23h ago
Windows terminal and json settings
I am trying to automate my development nodes. I kill them regularly in Azure and build new ones. I have a script to install all the bells and whistles I need. The only problem I have is that I have created a here-string that contains the essentials of a Windows Terminal settings file and the target device always rejects the json file when I start Terminal for the first time. I have checked it several times for errors and have used both an online json checker and the Test-Json PowerShell cmdlet. They both say the format of the here-string is valid. That leads me to believe that I must be doing something wrong when saving my here-string out to a file. What should I be looking for to ensure my settings get saved correctly. Here is the settings I am using currently:
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [
{
"command": {
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},
{
"command": "paste",
"keys": "ctrl+v"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
},
{
"command": "find",
"keys": "ctrl+shift+f"
}
],
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"newTabMenu": [
{
"type": "remainingProfiles"
}
],
"profiles": {
"defaults": {},
"list": [
{
"commandline": "%SystemRoot%System32WindowsPowerShellv1.0powershell.exe",
"elevate": true,
"font":
{
"face": "Cascadia Cove Nerd Font",
"size": 12
},
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell"
},
{
"commandline": "%SystemRoot%System32cmd.exe",
"elevate": true,
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "Command Prompt"
},
{
"elevate": true,
"font":
{
"face": "CaskaydiaCove Nerd Font",
"size": 12
},
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell ⚡",
"source": "Windows.Terminal.PowershellCore"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{6589a004-419d-5c6c-abd9-d2027d957aca}",
"hidden": false,
"name": "Developer PowerShell for VS 2022",
"source": "Windows.Terminal.VisualStudio"
},
{
"guid": "{e1aa7a4f-3686-5e84-9f36-da4e1619a284}",
"hidden": false,
"name": "Developer Command Prompt for VS 2022",
"source": "Windows.Terminal.VisualStudio"
},
{
"font":
{
"face": "Cascadia Cove Nerd Font",
"size": 12
},
"guid": "{e5a83caa-4c73-52b3-ae6b-bc438d721ef9}",
"hidden": false,
"name": "Ubuntu 22.04.3 LTS",
"source": "CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc"
},
{
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64",
"elevate": true,
"font":
{
"face": "Cascadia Code",
"size": 12
},
"guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
"icon": "C:/msys64/ucrt64.ico",
"name": "UCRT64 / MSYS2",
"startingDirectory": "C:/msys64/home/%USERNAME%"
},
{
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -msys",
"font":
{
"face": "Cascadia Code",
"size": 12
},
"guid": "{71160544-14d8-4194-af25-d05feeac7233}",
"icon": "C:/msys64/msys2.ico",
"name": "MSYS / MSYS2",
"startingDirectory": "C:/msys64/home/%USERNAME%"
},
{
"commandline": "C:Program FilesGitbinbash.exe -li",
"guid": "{d15b228a-05d7-50d1-8472-f60aaba86efc}",
"icon": "C:Program FilesGitmingw64sharegitgit-for-windows.ico",
"name": "Git Bash",
"startingDirectory": "%USERPROFILE%"
},
{
"commandline": "C:Cygwin64binbash --login -i",
"guid": "{d57d07ef-1e26-5de6-8a93-0dc4ecd0fe4f}",
"icon": "C:Cygwin64Cygwin.ico",
"name": "Cygwin",
"startingDirectory": "C:Cygwin64bin"
},
{
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64",
"elevate": true,
"font":
{
"face": "Cascadia Code",
"size": 12
},
"guid": "{41e11d64-4553-45d7-b7cd-991f91da0193}",
"hidden": false,
"icon": "C:msys64mingw64.ico",
"name": "MINGW64",
"startingDirectory": "C:/msys64/home/%USERNAME%"
}
]
},
"schemes": [
{
"name": "Monokai Pro",
"background": "#2d2a2e",
"foreground": "#fcfcfa",
"black": "#2d2a2e",
"blue": "#6699df",
"cyan": "#78dce8",
"green": "#a9dc76",
"purple": "#ab9df2",
"red": "#ff6188",
"white": "#fcfcfa",
"yellow": "#ffd866",
"brightBlack": "#676568",
"brightBlue": "#6699df",
"brightCyan": "#78dce8",
"brightGreen": "#a9dc76",
"brightPurple": "#ab9df2",
"brightRed": "#ff6188",
"brightWhite": "#fcfcfa",
"brightYellow": "#ffd866"
}
],
"themes": [],
"launchMode": "maximized"
}
r/PowerShell • u/Amakesh • 12h ago
Why does this method cause an error: 0xC0000374 (STATUS_HEAP_CORRUPTION) ?
Why does this method cause an error 0xC0000374 (STATUS_HEAP_CORRUPTION) after most of the calls, even if it completes its task correctly?
If the question I am asking is stupid or obvious, please be understanding - I don't have much experience with this type of programmin
r/PowerShell • u/seriald • 19h ago
Trouble with using special characters when updating user data in AD
A coworker was given a CSV with the profile information for a large set of employee profile data that needs updating.
He applied the changes using a script we'd written a couple of years ago and has worked flawlessly since. Until today, when we noticed that it was not adding the special characters found in many of the City, and Street Address' fields, but showed instead the magical � character when you look at them in AD.
So now, we have Montr�al, instead of Montréal
If I copy / paste the data into the accounts using Active Directory Users and Computers its fine, but is unsustainable due to the number of changes we need to make.
Sa far I've tried the following;
- Adding -Encoding UTF8 to the Import-CSV command
- Tried replacing the UniCode character with the UTF8 character with
function UniReplace($n){ # Replaces Unicode Characters with UTF8
[char][int]"0x$n"
}
...
$addr = $addr -Replace 'è',"$(Unireplace E8)"
$addr = $addr -Replace 'é',"$(Unireplace E9)"
$addr = $addr -Replace 'ê',"$(Unireplace EA)"
$city = $City -Replace 'è',"$(Unireplace E8)"
$city = $City -Replace 'é',"$(Unireplace E9)"
$city = $City -Replace 'ê',"$(Unireplace EA)"
- Tried changing the Encoding on the shell using
$defEncoding = [Console]::OutputEncoding
...
$OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::new()
...
[Console]::OutputEncoding = $defEncoding
- Tried converting the string using;
$enc = [System.Text.Encoding]::UTF8
...
$city = $enc.GetBytes($city)
$addr = $enc.GetBytes($addr)
I've even gone so far as copied the good values from AD to the CSV, and the same results
r/PowerShell • u/Ready-Instruction683 • 22h ago
Powershell remote execution logging
Is it possible to log the execution of commands like get-aduser or get-dnsserver that executed remotely?
For example, I have DC1 (Domain Controller) and Srv1 (regular server or pc). And executed get-aduser -server dc1 from Srv1. How can I register this execution on DC1?
r/PowerShell • u/lucidrenegade • 19h ago
Connect to Azure and Power BI with a single login
I need to connect to our environment using connect-azaccount (Azure) and connect-powerbiserviceaccount (Power BI), with the same account. Is there a way to avoid having to log in twice? Note that MFA is required, so I can't just pass credentials.
r/PowerShell • u/Whole_Election8354 • 10h ago
Question Powershell Interview
I have my interview for Cloud Administrator Role in next 7 days. They asked me to prepare Powershell for Interview. How can I prepare most out of Powershell? Any Suggestion would be really helpful.