Power Shell
15 TopicsWarning PowerShell ID 300
HI. Warning PowerShell ID 300 - Device not ready occurs at every startor 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 youSolved4.9KViews0likes13CommentsUnable to Execute PowerShell Script Commands in Microsoft Teams Session Established via Script
I encountered an issue while attempting to execute PowerShell script commands within a Microsoft Teams session established via a script. The script includes commands to connect to Microsoft Teams using the Connect-MicrosoftTeams cmdlet and subsequently execute other Teams-related commands. While the script executes without errors, the session does not seem to be fully established, resulting in the following error when attempting to execute subsequent commands: powershell : Get-CsTeamsClientConfiguration : Session is not established, run Connect-MicrosoftTeams before requesting access token At line:1 char:1 + powershell -File 'C:\Users\***********************\script.p ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Get-CsTeamsClie...ng access token:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError At C:\Users\****************************\script.ps1:8 char:1 + Get-CsTeamsClientConfiguration + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-CsTeamsClientConfiguration], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.Teams.ConfigApi.Cmdlets.GetCsTeamsClientCon figuration This issue is inconsistent, as the commands execute successfully when executed manually. Additionally, I've attempted to introduce delays in the script to allow for the session to fully establish, but the issue persists. This issue impacts the ability to automate tasks in Microsoft Teams using PowerShell scripts. Please let me know if there are any additional steps or information needed to address this issue effectively.1.1KViews0likes2CommentsGetting 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.1KViews0likes2CommentsHow 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 Jsonafter specific index. or position. For example:I have imported Jsonin $Jsonvariable 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 toCreate 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 toHave 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" } ] } }Solved28KViews0likes3CommentsCreating 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 YannikSchulzSolved7.4KViews1like7CommentsAutomating Daily Task
Hello, I am new to PowerShell and want to try using it to semi-automate a repetitive task. Any help would be greatly appreciated. I need to open multiple websites (10+) in IE (not updated yet), they also all have acknowledgement popups. They need to open in individual tabs. I am trying to set up an easy way for someone to verify the sites are up and running daily. 1. What I would like to do is have PowerShell open each site from a text file (list) in its own tab. 2. In the same session. 3. Automatically click the OK on the acknowledgement popup. 4. If the site fails to open display the error in the tab. And if this is not possible can a GUI be created in PowerShell, that lets you select each site, open them in the same session on a different tab? I am trying to do this so anyone can perform this task.1.4KViews0likes3CommentsPower shell script which shows list of RBAC role, Azure resource for all Users in Azure
Hi. I'm pretty new to PowerShell and trying out things. I'm trying to form a PowreShell script which shows list consists of Azure resource name, RBAC role, Username against it( all users included even in groups). I got to know that, we can see all users in group with this Get-AzAdGroupMember command. I tried to tweak for what I've found here in community into below, but I'm hitting to an error as shown below, I'm sure i was doing some syntax/silly mistakes, Can anyone please help me here? ForEach($ResourceinGet-AzResource){ $RoleAssignments=Get-AZRoleAssignment-ResourceGroupName$Resource.ResourceGroupName-ResourceName$Resource.Name-ResourceType$resource.type $new=Get-AzADGroupMember-DisplayName$RoleAssignments.DisplayName foreach($newin$RoleAssignment){ ForEach($RoleAssignmentin$RoleAssignments){ $Resource|Select-Object@{Name="AzureResourcename";Expression={$Resource.Name}}, @{Name="SignInName";Expression={$RoleAssignment.SignInName}}, @{Name="DisplayName";Expression={$RoleAssignment.DisplayName}}, @{Name="RoleDefinitionName";Expression={$RoleAssignment.RoleDefinitionName}} } } error message: Get-AzADGroupMember : A parameter cannot be found that matches parameter name 'DisplayName'. At line:3 char:30 }803Views0likes1Commentpowershell create a catalog file
Hi all, I am new to powershell. I am looking for powershell script to generate a catalog file which display all the subfolders and files underneath, better to comment out the subfolders, and only files listed, but should be listed just under the sunfolders. let say I have a folder called total_folder underneath there are many subfolders folder1 file1-1 fille1-2 folder2 file2-1 file2-2 file2-3 folder3 file3-1 ...... Now I would like to document these info into a catalog file as below ;----folder1---- file1-1 fille1-2 ;----folder2---- file2-1 file2-2 file2-3 ;----folder3---- file3-1 ......Solved1.8KViews0likes2CommentsUnable to Pass variable value to For each loop
Hello Everyone, I'm new to Poweshell, Someone tell what'swrong in below code? i want to pass $server value to for each loop but below code is failing #getServerList $Servers = Invoke-Sqlcmd -ServerInstance "localhost" -Query "SELECT [server_name] FROM [DBName].[dbo].[ServersList]" -Database "DBName" #Write-output $server foreach($Server in $Servers) { #SQl Query $sql = "SELECT @@SERVERNAME AS 'ServerName', DB_NAME(dbid) AS 'Database',name, CONVERT(BIGINT, size) * 8 AS 'size_in_kb', filename FROM master..sysaltfiles" Invoke-Sqlcmd -ServerInstance $server -query $sql -Database master -OutputAs DataTables | #WriteData Write-SqlTableData -ServerInstance localhost -Database master -SchemaName dbo -TableName DatabasesSizes -Force }1.3KViews0likes3Comments