PowerShell 7
10 Topicspowershell on mac
Hello Everyone, I’m new to using PowerShell on a Mac. I was given a PS1 script that needs to be run on a Mac device to check the files and folders of logged-in users. I managed to achieve this to some extent, but now I’m stuck on granting full disk access to the PWSH app via a Jamf Pro privacy payload. Since the PWSH app is not a signed package, I was unable to identify the “code requirements” to add a payload in Jamf Pro. Could you please share your best practices for deploying PowerShell and granting it full disk access via Jamf Pro?30Views0likes0CommentsCannot dot-source this command because it was defined in a different language mode.
Microsoft.PowerShell_profile.ps1: Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents, omit the '.' operator. I am getting this error when I open my PowerShellanywhere... I have few scripts present in my PS Profile,but this is failing with error,and I can't import, its blocking me to even set a property. $Host.Name = 'Test' InvalidOperation: Cannot set property. Property setting is supported only on core types in this language mode. Can someone please help me to get rid of this issue. Thanks!35KViews0likes12CommentsPowerShell support on Linux
I am trying to invoke Powershell 7.4 on Linux RHEL8 through a java program and submitting commands and reading output using streams. As soon as the powershell starts , the inputstream is reading some unknown characters from the powershell output for e.g. '[?1h' and '[?1l'. I need a way such that I don't read these characters. I tried setting the encoding in the input stream to UTF-8, but that didn't solve the problem. Would really appreciate if someone could provide some inputs on this.498Views0likes2CommentsRegarding the different output formats of Powershell Versions 5 and 7.
I use Exchange Online commands through Powershell. I have noticed that Powershell versions 5 and 7 work differently. And I would like to achieve an output format like Powershell version 5, but without using the "|Format-table" notation. Is it possible to rewrite the default values? Thank you. Powershell version information in use: PowerShell 5:5.1.22000.653 and PowerShell 7: 7.2.5Solved1KViews0likes3CommentsPowerShell Colors for Operator & Parameter
Hi all I have some weird behavior here. When I work with PowerShell 7 over the Windows Console Host, the Operator and Parameter color are completely black, and I can't see them when I type an Operator or Parameter. When I work with PS7 over the Windows Terminal, the Operator and Parameter are visible. Both windows have the same background color (0c0c0c) and I copied the value from the Windows Console Host PS7, to make sure it has the same value as the window from the Windows Terminal PS7. Has anyone a fix/explanation for this? Thanks. 🙂2.8KViews1like8CommentsHuge memory consumption using ForEach-Object -Parallel
I’ve a function that updates the stats in databases using ForEach-Object -Parallel. When I run it, to loop through the stats in a database and update them, it consumes a lot of memory on the server where I run the command from. In some cases 60/70Gb. Why is it doing that? Is there a way I can have the function release the memory used for each stat it updates? Function Update-Stats { <# $Database = '' $SqlInstance = '' Update-Stats -SqlInstance $SqlInstance -Database $Database #> [cmdletbinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$SqlInstance , [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Database ) BEGIN { $FlagOn = "DBCC TRACEON (7471, -1) WITH NO_INFOMSGS" $FlagOff = "DBCC TRACEOFF (7471, -1) WITH NO_INFOMSGS" $Satslist = @() $Srv = Get-SqlInstance -ServerInstance $SqlInstance $Srv | Get-SqlDatabase -Name $Database | %{ $Db = $_ "Processing $($Db.Name)" $Db.Tables | ?{$_.RowCount -gt 10} | % { $Table = $_ $Table.Statistics | %{ $Satslist += [PSCUstomObject]@{ SqlInstance = $SqlInstance Database = $Database Schema = $Table.Schema Table = $Table.Name RowCount = $Table.RowCount Stats = $_.Name } } } } $Satslist } PROCESS { if($Srv.VersionMajor -ge 14 ) { Invoke-Sqlcmd -ServerInstance $SqlInstance -Database $Database -Query "$FlagOn" $Tflag = $true } $Satslist | Sort-Object {Get-Random} | % -parallel { $Obj = $_ $Table = "[$($Obj.Schema)].[$($Obj.Table)]" $Stats = "[$($Obj.Stats)]" switch($($Obj.RowCount)){ {$_ -le 1000000} {$Percent = 20 ; break} {$_ -In 1000001..10000000} {$Percent = 15 ; break} {$_ -In 10000001..100000000} {$Percent = 10 ; break} {$_ -ge 100000001} {$Percent = 5 ; break} } "Invoke-Sqlcmd -ServerInstance $($Obj.SqlInstance) -Database $($Obj.Database) -Query `"Update Statistics $Table $Stats with Sample $Percent Percent`"" Invoke-Sqlcmd -ServerInstance $($Obj.SqlInstance) -Database $($Obj.Database) -Query "Update Statistics $Table $Stats with Sample $Percent Percent" } -ThrottleLimit 12 if($Tflag) { Invoke-Sqlcmd -ServerInstance $SqlInstance -Database $Database -Query "$FlagOff" } } END { } }3.3KViews0likes6CommentsJoin computer to domain with PowerShell 7
PowerShell 7 does not support the Add-Computer cmdlet and does not support WMI. I am assuming one needs to use CIM now to add a computer to a domain with PowerShell. Is that correct, or is there a new cmdlet we should be using that replaced Add-Computer? If CIM is required, does any have syntax used for doing this that works in both WPS 5.1 and PS 7.x? Would it involve using Invoke-CimMethod? Thanks NKSolved3.1KViews0likes1Comment