PowerShell CMDLETS
10 TopicsGet AzSentinelDataConnector no output
Hi All, I'm trying to export the list of all the data connectors using powershell module Az Security Insight. when I run the command Get-AzSentinelDataConnector, I have no output PS C:\Users\> Get-AzSentinelDataConnector -ResourceGroupName "Resourcegroup Name" -WorkspaceName "WorkSpace Name" PS C:\Users\> while using the command Get-AzSentinelAlertRuleTemplate I have all the alert rule as output PS C:\Users\> ... Kind : NRT LastUpdatedDateUtc : 30-Aug-22 12:00:00 AM Name : 5db427b2-f406-4274-b413-e9fcb29412f8 Query : AuditLogs | where ActivityDisplayName =~'Add member to role completed (PIM activation)' | where Result == "failure" ... RequiredDataConnector : {AzureActiveDirectory} Severity : High ... PS C:\Users\> Can someone support me? Thanks, lg960Views0likes3CommentsGet-ChildItem and Get-WmiObject cim_datafile showing different results
I am using below code to Check if the server is pinging then for Pingable Servers I am checking the Service Status and a file version but I see Get-ChildItem and Get-WmiObject cim_datafile showing different results. Get-WmiObject cim_datafile showing correct results. Looks like Get-ChildItem giving wrong results because it does not support -computername. any idea how can I use any cmdlet which does not support -computername in this script and still get correct results. function Get-EncaseInfo { [CmdletBinding()] param ( #[Parameter(Mandatory = $True)] #[string[]]$serverName ) process { $servers = (Get-Content D:\IT\servers.txt) $server_error = $false $servers_down = @() $servers_up = @() foreach ($server in $servers) { if(Test-Connection $server -Count 1 -ea 0 -Quiet){ #Write-Host $server "is Pinging" -BackgroundColor Green -ForegroundColor White $servers_up += "$server" }else{ #Write-Host $server "is not Pinging" -BackgroundColor Red -ForegroundColor White $servers_down += "$server" $server_error = $true }} Write-Host "" Write-Host "INFO: Below Servers are up" -ForegroundColor Green Write-output $servers_up if($server_error){ $error_msg = "Below Servers are not Pinging" Write-Host "" Write-Host $error_msg -ForegroundColor Red Write-output $servers_down }else{ Write-Host "INFO: ALL Servers are Pinging" -ForegroundColor Blue -BackgroundColor White} foreach ($Servup in $servers_up){ $Service=Get-Service -Name enstart64 -ComputerName $Servup -ErrorAction SilentlyContinue -ErrorVariable Errs #$EnVer = ((Get-ChildItem C:\Windows\system32\enstart64.exe).VersionInfo).FileVersion $EnVer = (Get-WmiObject cim_datafile -ComputerName $Servup -Filter {Name='C:\\Windows\\system32\\enstart64.exe'}).version [PSCustomObject]@{ 'ComputerName'=$Servup; 'Service'=$Service.Status; 'StartType'=$Service.StartType; 'EnVersion'=$EnVer; 'Error'=$Errs; } } } } Get-EncaseInfo | FT -AutoSize1.1KViews0likes1CommentUnable to run PowerShell cmdlets after module installation
Hi All, I have installed the Sharepoint Online Management Shell module in our remote desktop server. However I am unable to run any cmdlets after the installation is done. The module name isn't visible in the list of modules in the ISE as well. We have tried to install both through Windows INstaller as well as through the Install-Module cmdlet.2.1KViews0likes4CommentsUnable to upgrade to A7 and A8 using Azure PowerShell Cmdlet -
We are using this Cmdlet: https://docs.microsoft.com/en-us/powershell, to Upgrade the SKU to A7 and A8. We are able to scale to A7 from UI as shown below. On trying with PowerShell Cmdlet, we get the below error: Update-AzureRmPowerBIEmbeddedCapacity : Cannot validate argument on parameter 'Sku'. The argument "A7" does not belong to the set "A1,A2,A3,A4,A5,A6" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again. At line:70 char:121 + ... -Name $pbiEmbCap.Name -ResourceGroupName $resourceGroupName -Sku $sku + ~~~~ + CategoryInfo : InvalidData: (:) [Update-AzureRmPowerBIEmbeddedCapacity], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.PowerBI.UpdateAzurePowerBIEmbeddedCapacity Is it possible to update the parameter set including A7 and A8, so that we can use the same Cmdlet to upgrade the SKU888Views0likes1CommentBug in Get-CMSoftwareUpdateDeploymentStatus cmdlet
When I run the Get-CMSoftwareUpdateDeploymentStatus cmdlet I get the following message; Get-CMSoftwareUpdateDeploymentStatus : Operation could not complete because the currently connected account does not have the required security rights to perform this operation. I have the Full Administrator role I can run Get-CMPackageDeployment -DeploymentId "XX12008C" | Get-CMPackageDeploymentStatus and Get-CMApplicationDeployment -DeploymentId "{9462...43F34}" | Get-CMApplicationDeploymentStatus both work flawlessly but I can't do the same for Software Updates I run the following command; Get-CMSoftwareUpdateDeployment -DeploymentId "{7047...d3fe}" | Get-CMSoftwareUpdateDeploymentStatus644Views0likes0CommentsAlternative to invoke-expression
I am looking for alternate way to extract the value of the below powershell object without using invoke-expression invoke-expression "`$abc.properties.$subprop" or invoke-expression "`$abc.$subprop1" Where $abc is a powershell object in JSON format $subprop is having one of the Noteproperties of '$abc.properties'3.8KViews0likes1CommentMicrosoftTeams cmdlets not working with AccessToken
I am trying to run cmdlets from powershell module MicrosoftTeams (version 2.0.0) in a C# web application. I am using Authorization code flow and code from the answer provided in this post to acquire token: Acquire AAD token using ASP.Net web forms. Note: I had changed resource in the code to graph.windows.net to acquire AAD token. Token is acquired by using AuthenticationContext.AcquireTokenByAuthorizationCodeAsync method. Once the token is acquired, I run the following lines to create a powershell instance in C# and to import MicrosoftTeams Module. PowerShell pshell InitialSessionState iss; iss = InitialSessionState.CreateDefault2(); iss.ImportPSModule(new[] { "MicrosoftTeams" }); pshell = PowerShell.Create(iss); Then to connect with MicrosoftTeams, I run the following code: var connectCmd = new Command("Connect-MicrosoftTeams"); connectCmd.Parameters.Add("AadAccessToken", AccessToken); connectCmd.Parameters.Add("AccountId", "xxxxxxx@xxxxxx.onmicrosoft.com"); pshell.Commands.AddCommand(connectCmd); var result1 = pshell.Invoke(); Code works fine till here. After this I clear the shell commands and invoke the Get-CsTeamsCallingPolicy cmdlet: pshell.Commands.Clear(); pshell.Streams.Error.Clear(); pshell.AddScript("Get-CsTeamsCallingPolicy"); var result2 = pshell.Invoke(); After Invoke, I get an exception and this dialog pops up: Pressing 'Continue' brings back the same dialogue a couple of times. Exception details from this screen are: System.Collections.Generic.KeyNotFoundException was unhandled by user code HResult=-2146232969 Message=The given key was not present in the dictionary. Source=mscorlib StackTrace: at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key) at Microsoft.TeamsCmdlets.Powershell.Connect.Models.AzureSessionProvider.GetAccessToken(String resource, IEnumerable`1 scopes) in D:\a\1\s\src\Microsoft.TeamsCmdlets.PowerShell.Connect\Models\AzureSession.cs:line 80 at Microsoft.TeamsCmdlets.Powershell.Connect.TeamsPowerShellSession.GetAccessToken(String resource, IEnumerable`1 scopes) in D:\a\1\s\src\Microsoft.TeamsCmdlets.PowerShell.Connect\TeamsPowerShellSession.cs:line 82 at Microsoft.TeamsCmdlets.PowerShell.Connect.GetCsInternalAccessToken.ProcessRecord() in D:\a\1\s\src\Microsoft.TeamsCmdlets.PowerShell.Connect\GetCsInternalAccessToken.cs:line 61 at System.Management.Automation.CommandProcessor.ProcessRecord() After pressing continue for the 3rd time, control goes back to C# code, and I receive the following runtime exception: Exception calling "GetSteppablePipeline" with "1" argument(s): "Exception calling "GetRemoteNewCsOnlineSession" with "1" argument(s): "Run either Connect-MicrosoftTeams or new-csonlinesession before running cmdlets."" Trying to run this logic from the powershell editor shows similar behavior: Running the following two lines: $AccessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' Connect-MicrosoftTeams -AadAccessToken $AccessToken -AccountId 'xxxxxxx@xxxxxx.onmicrosoft.com' gives this result: Account Environment Tenant TenantId ------- ----------- ------ -------- xxxxxxx@xxxxxx.onmicrosoft.com AzureCloud xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx I then run Get-Team cmdlet: Get-Team -User xxxxxxx@xxxxxxx.onmicrosoft.com which results in this message: Get-Team : The given key was not present in the dictionary. At line:1 char:1 + Get-Team -User xxxxxxx@xxxxxxx.onmicrosoft.com + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-Team], KeyNotFoundException + FullyQualifiedErrorId : System.Collections.Generic.KeyNotFoundException,Microsoft.TeamsCmdlets.PowerShell.Custom.GetTeam Running cmdlet Get-CsTeamsCallingPolicy yields this: Exception calling "GetSteppablePipeline" with "1" argument(s): "Exception calling "GetRemoteNewCsOnlineSession" with "1" argument(s): "Run either Connect-MicrosoftTeams or new-csonlinesession before running cmdlets."" At C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.0.0\net472\SfBORemotePowershellModule.psm1:11369 char:13 + $steppablePipeline = $scriptCmd.GetSteppablePipeline($myI ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CmdletInvocationException If I run Connect-MicrosoftTeams directly from powershell without providing access token and accountid, I get the login screens and after login everything works fine i.e. I can run Get-Team and Get-CsTeamsCallingPolicy cmdlets successfully but I don't get this behavior when working with AadAccessToken. All the above code works fine if connecting to AzureAD module via Connect-AzureAD cmdlet like this both in web application and powershell editor: Connect-AzureAD -AadAccessToken $AccessToken -AccountId 'xxxxxxx@xxxxxxx.onmicrosoft.com' If someone has faced and successfully resolved this issue or have some tips on how to resolve this, please help. I have already tried a lot of things including searching for the specific exception messages and any possible solutions but found nothing that could help in this particular scenario, installed the latest version of MSTeams module, the previous version was old and did not have all the cmdlets that I am looking to work with. I installed the preview version of MSTeams module also to see if this issue is fixed in the upcoming release. Uninstalled the deprecated SkypeForBuisnessOnline Connector module, updated windows and so on. If you look at Example 4 in the Microsoft documentation for Connect-MicrosoftTeams, this is what I am trying to achieve.2.1KViews1like5Comments"Pre load" Powershell module
My new Powershell module did have a load time of several seconds. Using this in a production environment is not an option with this long load time. Is it possible to add this module to the "core" of powershell. So that it is already loaded before I start a new powershell session? King regards, Hans.Harms@centric.eu5.4KViews0likes6CommentsThe term <function-name> is not recognized as the name of a cmdlet, function, ...
This is my code. I'm trying to unzip files, edit them, and zip them back. For some reason functions DeGZip-File and GZip-File are not being recognized. Could anyone point out what could be wrong here? Function DeGZip-File { [CmdletBinding()] param($infile) $infile $outfile = ($infile -replace '\.gz$','') try { $input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read) $output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None) $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress) $buffer = New-Object byte[](1024) while($true){ $read = $gzipstream.Read($buffer, 0, 1024) if ($read -le 0){break} $output.Write($buffer, 0, $read) } return $outfile } catch { Write-Host "$_.Exception.Message" -ForegroundColor Red } finally { $gzipStream.Close() $output.Close() $input.Close() } } #Zip them back after adding the headers Function Gzip-File { [CmdletBinding()] param($outfile) $srcFile = Get-Item -Path $outfile $newFileName = "$($srcFile.FullName).gz" try { $srcFileStream = New-Object System.IO.FileStream($srcFile.FullName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read)) $dstFileStream = New-Object System.IO.FileStream($newFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None)) $gzip = New-Object System.IO.Compression.GZipStream($dstFileStream,[System.IO.Compression.CompressionMode]::Compress) $srcFileStream.CopyTo($gzip) } catch { Write-Host "$_.Exception.Message" -ForegroundColor Red } finally { $gzip.Dispose() $srcFileStream.Dispose() $dstFileStream.Dispose() } } $headerProcess = { #param($file,$headerArray) $file = $folder + "\" + $file $unZippedFile = DeGZip-File($file) $unZippedFile[1] $unZippedFile = $unZippedFile[1] $filedata = import-csv $unZippedFile -Header $headerArray $filedata | export-csv $unZippedFile -NoTypeInformation GZip-File $unZippedFile } function Add-Headers([string]$folder, [string]$schemaFilePath){ if($schemaFilePath -eq 'TallOptionsSchema.txt') { $tallOptionsSchema = Get-Content $schemaFilePath $strArray = [string[]]$tallOptionsSchema $headerArray = $strArray -join "`t" } else { $JSONFromFile = Get-Content -Raw -Path $schemaFilePath | ConvertFrom-Json $header = $JSONFromFile.schema.name $strArray = [string[]]$header $headerArray = $strArray -join "`t" } $filesToModify = Get-ChildItem $folder -Recurse -File foreach ($file in $filesToModify) { Start-Job -Name $file.Name -ScriptBlock $headerProcess -ArgumentList ($file,$headerArray) } } $folderPath = 'D:\Working\options' $schemafile = 'D:\Working\options\schema.json' Add-Headers $folderPath $schemafile Get-Job # Wait for it all to complete While (Get-Job -State "Running") { Start-Sleep 10 } # Getting the information back from the jobs Get-Job | Receive-Job Get-Job | remove-job -ForceSolved2KViews0likes1CommentPowerShell Command to return result at one script
Hi Folks!! Is there any way by which i can have result set that contains workspaces, dataset, dataflow, report, users etc at one script. I really don't want to pass any parameter to the script if there any restriction on number of values of parameter to enter. Thank Amit742Views0likes0Comments