powershell

Iterate over JSON and remove JSON element in PowerShell

左心房为你撑大大i 提交于 2021-02-07 20:53:04
问题 Pasted below is my sample JSON file. Loop over all the unqiue properties For each unique property check the value of "x-visibility": "Private" object. If this is "Private" then remove the entire object. I m trying to do this foreach ($p in $apijson.paths.PSObject.Properties.Value) { $get = $p.get.'x-qlik-visibility' -eq 'Private' if ($get -eq 'True') { Write-Host 'Removing Object :'$p # Remove-ItemProperty -Name $p.get $apijsonNew.PSObject.Properties.Remove($p) } } { "swagger": "2.0", "info":

Powershell SQL server database connectivity and connection timeout issue

给你一囗甜甜゛ 提交于 2021-02-07 20:52:04
问题 I've a powershell script connecting to SQL server 2012 database running a SQL query and result set into data table to send formatted email to relevant parties. Below is the code snippet where issue is: $CBA = New-Object System.Data.DataSet "CBAData" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=DataSource;Initial Catalog=DataCatalog;Integrated Security = False;Connection Timeout=800;User ID = user; Password =pwd;") $adapter = New-Object System.Data.SqlClient

Powershell SQL server database connectivity and connection timeout issue

*爱你&永不变心* 提交于 2021-02-07 20:51:38
问题 I've a powershell script connecting to SQL server 2012 database running a SQL query and result set into data table to send formatted email to relevant parties. Below is the code snippet where issue is: $CBA = New-Object System.Data.DataSet "CBAData" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=DataSource;Initial Catalog=DataCatalog;Integrated Security = False;Connection Timeout=800;User ID = user; Password =pwd;") $adapter = New-Object System.Data.SqlClient

Iterate over JSON and remove JSON element in PowerShell

我与影子孤独终老i 提交于 2021-02-07 20:51:13
问题 Pasted below is my sample JSON file. Loop over all the unqiue properties For each unique property check the value of "x-visibility": "Private" object. If this is "Private" then remove the entire object. I m trying to do this foreach ($p in $apijson.paths.PSObject.Properties.Value) { $get = $p.get.'x-qlik-visibility' -eq 'Private' if ($get -eq 'True') { Write-Host 'Removing Object :'$p # Remove-ItemProperty -Name $p.get $apijsonNew.PSObject.Properties.Remove($p) } } { "swagger": "2.0", "info":

Powershell SQL server database connectivity and connection timeout issue

假装没事ソ 提交于 2021-02-07 20:49:24
问题 I've a powershell script connecting to SQL server 2012 database running a SQL query and result set into data table to send formatted email to relevant parties. Below is the code snippet where issue is: $CBA = New-Object System.Data.DataSet "CBAData" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=DataSource;Initial Catalog=DataCatalog;Integrated Security = False;Connection Timeout=800;User ID = user; Password =pwd;") $adapter = New-Object System.Data.SqlClient

Powershell capture both output and verbose information in different variables

佐手、 提交于 2021-02-07 20:35:32
问题 Is it posible to capture both output and verbose information into two different variables? My requirement: I am creating a gui with powershell and wpf where it has a richtextbox which display only verbose and errors. For example if i execute get-dscconfiguration -verbose , verbose stream should go to richtextbox and output of that cmdlet should be asigned to a variable for further manuplation. Please help me achive this. Thank you! -vinay 回答1: You can capture one stream to a variable or

Powershell capture both output and verbose information in different variables

那年仲夏 提交于 2021-02-07 20:34:44
问题 Is it posible to capture both output and verbose information into two different variables? My requirement: I am creating a gui with powershell and wpf where it has a richtextbox which display only verbose and errors. For example if i execute get-dscconfiguration -verbose , verbose stream should go to richtextbox and output of that cmdlet should be asigned to a variable for further manuplation. Please help me achive this. Thank you! -vinay 回答1: You can capture one stream to a variable or

A Powershell function to convert unix time to string?

ε祈祈猫儿з 提交于 2021-02-07 19:51:00
问题 I'm trying to read the date fields of Firefox places.sqlite datedase using ADO.NET and PowerShell. Obviously these fields are in Unix time. I'm looking for a conversion to .Net datetime or string Edit: I want to bind the datarow to a WPF GridView. I need either a way to do the conversion within the SQL query or some way while binding the datarows to the grid. 回答1: Something like this should put you on the right path: [TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds(

How do I use WMI to get the current OU of a computer and list all other computers in that OU?

被刻印的时光 ゝ 提交于 2021-02-07 19:50:22
问题 I'm using WMI and am trying to find a powershell script that will allow me get the OU of the local computer and then get a full list of computers in that OU. 回答1: Here you go: $ComputerName = '<Name of Computer>'; $Computer = Get-WmiObject -Namespace 'root\directory\ldap' -Query "Select DS_distinguishedName from DS_computer where DS_cn = '$ComputerName'"; $OU = $Computer.DS_distinguishedName.Substring($Computer.DS_distinguishedName.IndexOf('OU=')); $ComputersInOU = Get-WmiObject -Namespace

How do I use WMI to get the current OU of a computer and list all other computers in that OU?

核能气质少年 提交于 2021-02-07 19:50:03
问题 I'm using WMI and am trying to find a powershell script that will allow me get the OU of the local computer and then get a full list of computers in that OU. 回答1: Here you go: $ComputerName = '<Name of Computer>'; $Computer = Get-WmiObject -Namespace 'root\directory\ldap' -Query "Select DS_distinguishedName from DS_computer where DS_cn = '$ComputerName'"; $OU = $Computer.DS_distinguishedName.Substring($Computer.DS_distinguishedName.IndexOf('OU=')); $ComputersInOU = Get-WmiObject -Namespace