Power Shell
27 TopicsPowershell script to find out Teams policies by users
Hey everyone, do you know if there is a way to run a script to find what Teams policies are assigned to what user? We have a private channel policy in place- I would like to find out a list of users that policy is assigned to. Also, if you delete a user from a custom policy does that user get the default policy? Thanks!109KViews2likes16CommentsHow to add a new set of key & values in json file.
Problem Statement: I want to add a set of new key & value in existing parsed Json after specific index. or position. For example: I have imported Json in $Json variable and then I wanted to add new sets of property right after property name 'Service1'. I able to make the script working out for me. However, not able to add new sets of key & value or property after specific position in file. PowerShell Code: function Get-EnvironmentManifest([string]$Filename) { $Settings = Get-Content -Path $Filename -Encoding UTF8 | ConvertFrom-Json -ErrorAction STOP return $Settings } if (([System.Net.Dns]::GetHostByName($env:computerName)).HostName.Split('.')[0] -notmatch "UAT*") { $EnvironmentString = (([System.Net.Dns]::GetHostByName($env:computerName)).HostName.Split('.')[0].Split('-')[1]).ToUpper() for ($i = 1; $i -lt 5; $i++) { $ServiceName = 'Service' + [char](65 + $i) $HastTable = [ordered] @{"Name" = "Service1"; "ProfileType" = "Windows"; "ServiceName" = "$ServiceName";} $Settings = Get-EnvironmentManifest -Filename $TargetJSON $Asset = New-Object -TypeName PSObject $Asset | Add-Member -NotePropertyMembers $HastTable -TypeName 'Asset' $Settings.Profiles.Services += $Asset $Settings | ConvertTo-Json -Depth 3| Set-Content -Path $TargetJSON } } I Was Able to Create Following JSON Using Above PowerShell Code: { "Environment": {}, "Profiles": { "Services": [ { "Name": "A" }, { "Name": "B" }, { "Name": "C" }, { "Name": "D" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceA" }, { "Name": "E" }, { "Name": "F" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceB" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceC" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceD" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceE" } ] } } But I Want to Have Following Json: { "Environment": {}, "Profiles": { "Services": [ { "Name": "A" }, { "Name": "B" }, { "Name": "C" }, { "Name": "D" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceA" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceB" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceC" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceD" }, { "Name": "Service1", "ProfileType": "Windows", "ServiceName": "ServiceE" }, { "Name": "E" }, { "Name": "F" } ] } }Solved30KViews0likes3Comments[System.Drawing.Bitmap] not found in powershell,but at powershell ise is exist!
hello everyone: I have a question, such as a title. - - - - - - - - - - - - - - -powershell - - - - - - - - - - ---------------------- PS C:\> [System.Drawing.Bitmap] [System.Drawing.Bitmap] CategoryInfo:InvalidOperation:(System.Drawing.Bitmap:TypeName)[],RuntimeException FullyQualifiedErrorId:TypeNotFound ----------------------------- powershell ise ------------------- ---------------------- PS C:\> [System.Drawing.Bitmap] IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Bitmap System.Drawing.Image ------------------------------version------------------------------------------------ Name Value ---- ----- PSVersion 5.1.17763.771 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.771 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 PS:Powershell is the same version as powershell ise11KViews0likes2CommentsCreating Powerplans
Hello, I want to create a script using Powershell to set a default power plan. I already found something for the good old CMD but nothing yet for Powershell, so maybe you guys can help?! The Settings: Powerbutton: When I press Powerbutton: Shutdown - Shutdown When I press Sleepbutton: Nothing - Nothing When i close the lid: -Nothing -nothing Plan-Settings: Turn off Display: 15min - never Put it to sleep: Never - Never I would appreciate if you could give me some advice on how to use Powershell creating "Power-Plans". Greetings Yannik SchulzSolved8.5KViews1like7CommentsBasic ssh works but X11 does not
I have the basic features of <ssh remotehostname> working right now. By "working" I mean that I can successfully connect to another machine (Linux machine) through an ssh session in powershell using a command like <ssh remotehostname>. I've already setup my /.ssh/config file and public keys which works quite nicely. However, I cannot get X11 to work. Any time I try to start this GUI application (which happens to be the eclipse IDE on this linux machine) it gives the following error (PowerShellError.png). I've went ahead and setup cygwin64 and it's working like a charm. I have X11 working just fine and can launch this same GUI application just fine. I'm attaching this output as well (Cygwin64.png). What is going on here? How can I troubleshoot this error. I don't believe this missing package called "cairo" is the issue since it happens on cygwin as well. I also get this missing "cairo" package error even when I'm directly working from this linux machine. I think the issue here is related to some display setting or powershell setting that is not being applied??? I do not know much about powershell so the more detailed you are is much appreciated.8.5KViews0likes5CommentsWarning PowerShell ID 300
HI. Warning PowerShell ID 300 - Device not ready occurs at every start or starting W.P.S 5.1. - <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> - <System> <Provider Name="PowerShell" /> <EventID Qualifiers="0">300</EventID> <Version>0</Version> <Level>3</Level> <Task>3</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2023-02-09T13:24:44.9356909Z" /> <EventRecordID>657</EventRecordID> <Correlation /> <Execution ProcessID="7524" ThreadID="0" /> <Channel>Windows PowerShell</Channel> <Computer>Windows-11</Computer> <Security /> </System> - <EventData> <Data>Dispositivo non pronto.</Data> <Data>ProviderName=Microsoft.PowerShell.Core\FileSystem ExceptionClass=IOException ErrorCategory= ErrorId= ErrorMessage=Dispositivo non pronto. Severity=Warning SequenceNumber=13 HostName=ConsoleHost HostVersion=5.1.22621.963 HostId=f904787d-5901-4255-b784-310a76225a8b HostApplication=powershell.exe -ExecutionPolicy Restricted -Command Write-Host 'Final result: 1'; EngineVersion= RunspaceId= PipelineId= CommandName= CommandType= ScriptName= CommandPath= CommandLine=</Data> </EventData> </Event> and the following warning appears: And if I open the link I get version 7 which I already have installed. Is there a solution to avoid this warning? Thank youSolved5.3KViews0likes13CommentsUnable to invoke jupyter notebook in powershell (Unable to create process) (No such file/directory)
I have two installs of python and have added the following to my user path environment variable... C:\Python\Python36\ C:\Python\Python36\Scripts C:\Python\Python37 C:\Python\Python37\Scripts I have installed jupyter notebook to the following location... C:\Python\Python37\Scripts\ You can clearly see that jupyter-notebook.exe is indeed there. However, no matter what command I use I can't start it. If I navigate to the directory where the exe is I can start the jupyter-notebook.exe just fine. Therefore, why can't I invoke "python37 jupyter-notebook.exe" from my home directory or anywhere other than the location it resides? It's in my user path environment variable so I'm lost on what else to try.4.8KViews0likes0CommentsSharePoint - How to export SharePoint User Profile Information values in CSV using powershell
Hi All, I'm new to SharePoint and I'm trying to automate the process of exporting all the user's information to a CSV file using Powershell. I've got some sample PowerShell script but it doesn't seem to work, assuming it's due to one of the below reasons. 1) Do I have to run PowerShell as admin? 2) Do I have to be an admin on the SharePoint site? Any other ideas on how to achieve this? Thanks in advance. Best Regards, Abhi3.7KViews0likes5CommentsGet the all info for "Additional Information" attributes for all meeting rooms - PowerShell
Hi Tech Folks, I am trying to get the info audio, video, display, tags, etc. which is located under each meeting room or basically a resource which the type is Room. Exchange Admin Center --> Resources --> Select Any Meeting Room (TYPE:ROOM) --> Additional Information I used this command which is working fine and reveals everything about the room and its properties , but NOT those above info I m looking for: Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select * | Format-list How can I get those Additional Attributes by that PS command? Any thoughts? Thanks for your inputsSolved2.3KViews0likes3CommentsGetting all virtual machines in a Hyper-V cluster using Python and WinRM
Hello, I am trying to use Python and WinRM to retrieve a list of all virtual machines in a Hyper-V cluster. I have a PowerShell script that works to retrieve the virtual machines owned by the current node, but I am having trouble modifying it to retrieve all virtual machines in the cluster. Here's the current script that retrieves the virtual machines owned by the current node: # Create a PowerShell session on the host machine session = winrm.Session(host, auth=(username, password),transport='ntlm') # Define the PowerShell command to retrieve the list of virtual machines in the cluster ps_script = """ $nodes = Get-ClusterNode Write-Output $nodes $vm_list = Get-ClusterGroup -Cluster $env:computername | Where-Object {$_.GroupType -eq 'VirtualMachine' -and $_.OwnerNode.Name -in $nodes.Name} | Get-VM $vm_names = $vm_list.Name Write-Output $vm_names """ # Execute the PowerShell command and retrieve the output result = session.run_ps(ps_script) if result.status_code == 0: # Parse the output to get the list of virtual machines vm_info = result.std_out.decode('utf-8').strip() # Print the list of virtual machines print(vm_info) else: # Print the full error message print("Error message: " + result.std_err.decode('utf-8').strip()) Can anyone help me modify this script to retrieve all virtual machines in the cluster, regardless of which node owns them? Thank you in advance for your help!2.2KViews0likes2Comments