Questions tagged [powershell-core]

Use this tag for questions about writing and executing scripts for PowerShell Core, the cross-platform command line and scripting utility from Microsoft. Questions about the Windows-only PowerShell should be tagged [powershell]. Questions about system administration should be asked on SuperUser.

3
votes
1answer
58 views

Binary PowerShell Core cmdlet using SimpleInjector results in FileNotFoundException

The Question I'm trying to create a PowerShell Core binary cmdlet library that uses SimpleInjector, but cannot figure out why it's resulting in a FileNotFoundException when debugging it with Visual ...
2
votes
0answers
38 views

PowerShell: the difference in expressions

I've been experimenting with the different forms of operators/expressions involving parentheses, but I can't find an explanation for an interaction I'm running into. Namely, ( ) and $( ) (...
0
votes
0answers
14 views

VSTS Hosted Agent (Hosted Linux Preview 2) - Environment variables are gone

In my build pipeline i have a powershell task which executes a script to gather information from the build. It needs agent and build variables which it would fetch from the environment variables. ...
1
vote
1answer
25 views

Subpath without leading '.'

I'm trying to find a way to produce qualified names of sub-paths sans the leading "./", for all directories under my current location: $dirs = Get-ChildItem -Directory -Recurse . I'd use Resolve-...
0
votes
0answers
40 views

PowerShell Core Script deployed as AWS Lambda function fails to remote connect into Windows EC2 Instance using the Commandlet new-pssession

AWS Recently announced Lambda Support for PowerShell Core. Reference URL https://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/ Followed the steps given in the URL and ...
0
votes
0answers
18 views

Powershell core - regular expression

Is there a problem with regular expressions in powershell. Running on Linux. So, as an example. PS> "Does this get found" | select-string -Pattern "^[A-Z ]*$" Does this get found But on bash ...
0
votes
0answers
44 views

Read and run Select-String cmdLet in network folder, write to local folder

Am at last getting my script working as intended. Hopefully last issue is that i have only read-access to a network drive. This is okay since it is a somewhat critical place to operate in. Makes me ...
1
vote
2answers
32 views

Is it possible to create namespaced environment variables in powershell? (like $custom:JSenv)

I was wondering if I can create a PSDrive like Env: for my project specific environment variables, like $custom:JSenv, $custom:root etc. instead of populating the Env: PSDrive. I tried using New-...
1
vote
1answer
63 views

How to call function from another function inside the same script in Powershell/Powershell Core?

Consider the example script code importer.ps1 #!/usr/bin/env pwsh New-Item -Path $profile -Force | Out-Null; function main { if (Test-AlreadyImported) { Write-Host "Already Imported."; ...
0
votes
1answer
76 views

Azure Traffic Manager make sure no traffic is flowing after disabling endpoint

I am trying to find a powershell command which helps find out a way that there is no open connections or any traffic is flowing to endpoint1 or confirm traffic is moving smoothly to endpoint2 after ...
-1
votes
1answer
59 views

What would this batch-command look like in PowerShell?

This works nicely in commandline. Have tried running it in PowerShell without luck, syntax is obviously different. for %%f in (*.hej) do ( findstr /V "Channel Record TESTBOOL OK OPC Item ...
0
votes
0answers
35 views

Get-Counter Command is not working in Powershell Core

I have installed Powershell Core from Here. but in this PowerShell core Get-Counter command is not working. Is there any way to run Get-Counter command in PowerShell Core.
1
vote
0answers
64 views

Invoke-Sqlcmd cmlet missing in Powershell core sqlserver module for linux

I am using latest version of Powershell core on Linux Ubuntu 16.04. I am trying to query a sql server database using powershell's invoke-sqlcmd cmdlet. (Yes I have installed the sqlserver module) I ...
0
votes
0answers
53 views

How to run powershell commands in remote computers using AWS Lambda C# .Net Core 2.1

How to run powershell commands in remote computers using AWS Lambda C# .Net Core 2.1 ? Added the nuget package https://www.nuget.org/packages/System.Management.Automation/6.1.0-rc.1
2
votes
1answer
27 views

What is an appropriate debugging workflow for Powershell Core modules?

My company has a .NET Powershell module, written in C# to allow advanced users to automate tasks in our product. Currently it targets Powershell 5 using .NET 4.6.1. We would like to allow customers ...
1
vote
1answer
68 views

Is it possible to install the PKI module on Powershell Core?

I'd like to use the various commands from Powershell 5's PKI module: $ Get-Command -module PKI CommandType Name Version Source ----------- ---...
0
votes
0answers
37 views

How to disable package integrity checking via NuGet.exe?

Since v 4.6 default NuGet client (NuGet.exe) checks package integrity on restore, if applicable. I've faced with this issue when restoring System.Management.Automation for .NET Core projects. It ...
2
votes
0answers
52 views

How to create a permanent environment variable for Linux in PowerShell

How to create, set and update a permanent environment variable for Linux in PowerShell Core. The following solution works properly, but only when I run the script on Windows: [Environment]::...
0
votes
1answer
46 views

Remote Execution of Powershell Command with PowerShell-Core Version

I am trying to execute Powershell command remotely, my problem is that the Powershell is used is version 4.0, and I want to execute my command remotely using Powershell Core 6.0.4. I tried to use ...
0
votes
1answer
22 views

On Windows platforms, can Powershell Core use Windows Powershell specific features?

There are several features of Windows Powershell that are not supported in Powershell Core. Since Powershell Core is being actively developed in favor of Windows Powershell, on a Windows platform can ...
0
votes
1answer
33 views

Loading .xls file with macros using PowerShell Core for Mac

I am trying to load an Excel file using PowerShell Core for Mac but I am encountering an issue with New-Object. It's failing on the very first line $Excel = New-Object -ComObject Excel.Application ...
1
vote
2answers
57 views

Multipart form script works perfectly in PowerShell but not in PowerShell core

The following code works perfectly in PowerShell on a Windows Server $user ="XXXXX" $pass ="XXXXX" $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $...
9
votes
1answer
99 views

Can I customise the 'not recognized as the name of a cmdlet' error in Powershell?

Say I make a typo on the command line: whih foo Powershell returns: whih : The term 'whih' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling ...
0
votes
3answers
101 views

“Install-Module -name AzureAD” fails with error on PS6 with MacOSX

I was able to install Powershell Core on MacOSX and now I'm trying to administer an Azure AD instance from the same. When I install the AzureAD module, I get the following error PS /Users/c> ...
11
votes
2answers
269 views

Powershell 'x or y' assignment

There are several languages that provide either a defaulting or logical or mechanism for assignment: a = b || c; a = b or c a="${b:-$c}" a = b ? b : c; So far the only equivalent I've found in ...
2
votes
1answer
35 views

Remove region within HTML

I want to remove a self imposed region within HTML. I've worked out the correct regex, which I've proved in Expresso, and the correct section is highlighted. I ran this in multiline mode, and have ...
0
votes
1answer
46 views

Why does Get-CimInstance CIM_LogicalDisk return two types?

Why does Get-CimInstance CIM_LogicalDisk return both a Win32_LogicalDisk and a Win32_MappedLogicalDisk? There is a Win32_MappedLogical disk CIM class, but there is no Cim_MappedLogicalDisk` class. ...
1
vote
1answer
51 views

Add-Content bytes fails with PowerShell Core

I'm using PowerShell Core v6.0.2, and trying to write out an array of bytes to a file. This works fine in regular PowerShell but fails with PowerShell Core $jsonstr = Get-Content $inputfilename $...
0
votes
0answers
12 views

Stream redirection when wrapping Powershell Core with Bash

Powershell has six streams, Host, Output, Verbose, Warning, Debug and Error. When running pwsh on Mac or Linux, all streams except for Error appear on the pwsh process's stdout, and only the Error ...
1
vote
1answer
46 views

Linux to windows - Execute .exe remotely

We have requirement to execute .exe with parameters remotely from Linux machine to Windows 10. So we have installed PowerShell in CentOS. Following are the commands we used: Invoke-Command -HostName ...
0
votes
0answers
19 views

Powershell Core not finding applications by Path

Environment: Powershell Core on Ubuntu1804 (which is on Windows 10). In the folder /mnt/c/_pupdev/dbt-project-bakeoff/virtualenv_rdl/bin/, I have the file newpip My path is set to /mnt/c/_pupdev/dbt-...
0
votes
1answer
70 views

How to get “pwsh -c {…}” to pass through the powershell command's expression result on Ubuntu?

In a PHP script on my Ubuntu 16 server I want to be able to check if Powershell has a certain module installed, which I tried to do by the line pwsh -c {Get-Module -ListAvailable -Name "VMware....
0
votes
0answers
97 views

PowerShell pscmdlet unit testing with C#

Need some help understanding how to unit test a PowerShell module I'm creating. I'm using the PowerShellStandard.Library package to create some cmdlets. My commands are deriving from pscmdlet and not ...
0
votes
0answers
25 views

How to approach testing with binary powershell modules

I've written a binary PowerShell module, which I'd like to test with unit-tests. The problem I'm encountering is, that my mocking does not seem to work. There's no errormessage or whatsoever, which ...
1
vote
1answer
126 views

Is it possible to run PowerShell Core in a Linux dotnet container?

I can see there is no Powershell present in microsoft/dotnet: C:\> docker run -it microsoft/dotnet:2.1-sdk bash root@5397dac12c1e:/# pwsh bash: pwsh: command not found When I try to add it in the ...
0
votes
0answers
31 views

Async event not firing in Powershell Core 6

I have a powershell module that uses async timer events to monitor and trigger actions. It works fine when kicked off in the powershell terminal in windows. I was interested to find out if it would ...
0
votes
0answers
224 views

Invoke SQL command not working in Power shell core 6.0.2

invoke sql command is not working it throws a below error can some one help me with it invoke-sqlcmd : The term 'invoke-sqlcmd' is not recognized as the name of a cmdlet, function, script file, ...
0
votes
1answer
168 views

Using powershell jobs for run from c#

I need to run a powershell script that runs jobs. I test this possibility with this code: var psscript ="$j = Start-Job -ScriptBlock { Write-Host 1 }; Wait-Job $j; Receive-Job $j"; using (var ps = ...
2
votes
1answer
122 views

Cross edition exception handling with Powershell web cmdlets

I have an existing PowerShell module that runs against Windows PowerShell 5.1. It depends heavily on the Invoke-WebRequest and Invoke-RestMethod cmdlets which have some fairly significant changes ...
0
votes
0answers
44 views

How to save line numbers in scripts?

Trying to tell a script to save line number as variable. Works fine in Windows Powershell, and if I put it into PS Core by hand. $num = Select-String source.txt -pattern "XXXXX" | Select-Object -...
0
votes
0answers
49 views

Is it possible to use powershell core and powershell 5.x in the same program?

I have a traditional Windows program that is written in C# using powershell 5.x .Net framework. Now I'd like to add the feature to remotely manage Linux system using Powershell core. The problem is ...
0
votes
0answers
62 views

C# console app that calls PowerShell 5.1 commands - Visual Studio Code

I am writing a Windows Console app that will run as a service. The console app must be able to execute Windows PowerShell 5.1 commands. The commands that I need are not yet compatible with Powershell ...
0
votes
1answer
41 views

PowerShell Core in Debian Docker Container Error

I'm new to Docker and am trying to create a Docker image with Raspbian base and PowerShell Core installed. EDIT: Updated Dockerfile to include libicu52 package, which resolved the main error: lack of ...
0
votes
1answer
54 views

Add CentOS machine to domain using powershell?

I want to add my CentOS machine to my Windows Domain using PowerShell command, (after PowerShell installation on the centos server). I can do it with linux native commands with realm but i dont want ...
1
vote
1answer
77 views

PowerShell Core Encryption on Linux

Is there any way to load Windows PowerShell assemblies or class files into PowerShell Core on a Linux system? I am trying to run a script that calls the "System.Security.Cryptography.AesManaged" class ...
0
votes
1answer
690 views

how to get the HostName from powershell?

How do I get the hostname for dur from powershell? PS /home/thufir/powershell> PS /home/thufir/powershell> ./hostname.ps1 ...
0
votes
1answer
352 views

Toggle between fullscreen editor and terminal in VS Code

As a Windows systems admin, I use PowerShell quite a lot. With the release of PS Core, and the implication that the ISE is dead, I've started to try to use VS Code as my day to day tool. One feature I'...
3
votes
1answer
128 views

Custom prompt prints twice in PowerShell Core 6.0 on Ubuntu

I have a custom PowerShell prompt function in my $PROFILE and it works fine on Windows for PS 5.1 and PS Core 6.0, but not for PS Core 6.0 on Ubuntu 17.04. On Ubuntu prompt gets duplicated: To make ...
2
votes
2answers
225 views

How to I remove the Powershell start text?

Powershell 6 has a Unix-style /etc/issue that mentions a link to the docs. PowerShell v6.0.0 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/pscore6-docs Type 'help' to get ...
1
vote
1answer
288 views

How to install powershell on MacOS

I've installed the powershell PKG file and I can launch the powershell from Applications However, I would like to integrate it into the Terminal on Mac. According to this link, after installing the ...