powershell-4.0

Can you import .CSV data into SQL Server using commands from Powershell 3 or 4?

*爱你&永不变心* 提交于 2019-12-24 19:37:01
问题 Is there a Powershell script for PowerShell version 3 or version 4 that allows you to import values from a .CSV file into a SQL table? I'm trying to figure out whether I can script a PowerShell job to import data, using enterprise Servers running older versions of PowerShell (It would be preferred if this can be done without importing any additional modules) (Nice to have, but not necessary) Also interested to know if there's a way to report the success or failure of that job, to a log file?

Accessing output from Start-Process with -Credential parameter

拈花ヽ惹草 提交于 2019-12-24 13:43:19
问题 The following opens in a new window, I guess because the new window represents the process running under a different credential: Start-Process ipconfig -Credential domain\user -NoNewWindow The documentation here doesn't seem to point this out. Considering this is occuring, and I need to run with with elevated privilages, how can I get the output of the above command back into my console? 回答1: Use the -RedirectStandardOutput parameter to redirect the output to a file. Then, read the file

Get a list of users from Atlassian's Cloud / On-Demand Service

旧街凉风 提交于 2019-12-24 00:45:37
问题 I'm trying to pull a list of users from our Atlassian Confluence/Jira instance. However I'm struggling to find good documentation on what REST services are available, and it seems the SOAP services are deprecated. The following code does get results, but we have over 100 users, and this returns 0. if(-not ($credentials)) { #put this here so I can rerun the same script in the same IDE session without having to reinput credentials each time $credentials = get-credential 'myAtlassianUsername' }

How to use a default value with parameter sets in PowerShell?

梦想的初衷 提交于 2019-12-23 17:24:02
问题 I have this function Function Do-ThisOrThat { [cmdletbinding()] param ( [Parameter(Mandatory = $false, ParameterSetName="First")] [string]$FirstParam = "MyFirstParam", [Parameter(Mandatory = $false, ParameterSetName="Second")] [string]$SecondParam ) Write-Output "Firstparam: $FirstParam. SecondParam $SecondParam" } If I call the function like this Do-ThisOrThat I want it to detect that the $FirstParam has a default value and use that. Is it possible? Running it as is only works if I specify a

Powershell version 5 Copy-Item -FromSession cannot be found

夙愿已清 提交于 2019-12-23 15:28:40
问题 I'm trying to copy some log files from a remote session via the -FromSession paramter of the Copy-Item cmdlet. On the calling machine I've PS version 5 installed. When running the script I get following error: Copy-Item : A parameter cannot be found that matches parameter name 'FromSession'. When I'm calling $PSVersionTable on the source machine I get following output: PSVersion 5.0.10586.672 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.10586.672 CLRVersion 4.0.30319.42000

Find duplicate values in one of the two columns in a text file

不羁岁月 提交于 2019-12-23 11:39:10
问题 I have a text file with two values in each line separated by a space. Now I want to know duplicate values in one of the columns. Is it possible to achieve this using Windows powershell. Given a text file: Apple Fruit Banana Fruit Carrot Vegetable Desired output is: (I want to find duplicates in second column) Fruit 回答1: You could use the Import-CSV cmdlet and specify a whitespace delimiter to easy get access of the second column. Then you can group the objects using the second column and

Trying to upload files to subfolder in Sharepoint Online via Powershell

笑着哭i 提交于 2019-12-22 00:27:57
问题 I am new to Powershell and I am trying to upload files from a local folder into Sharepoint online. I seem to get the files into the library, but not into the second subfolder where i want them. Script so far: #Specify tenant admin and site URL $User = "admin@contoso.no" $SiteURL = "https://contoso.sharepoint.com" $Folder = "E:\LocalFolder" $DocLibName = "Libraryname" $FolderName = "Folder/SubFolder" #Add references to SharePoint client assemblies and authenticate to Office 365 site – required

PowerShell XML SelectNodes fails to process XPath

依然范特西╮ 提交于 2019-12-20 17:35:17
问题 I want to get a list of all project references in my csproj file using PowerShell. Currently I've the following approach: [xml]$csproj = Get-Content MyProject.csproj $refs = $csproj.SelectNodes("//ProjectReference") foreach($ref in $refs) { # Later on output more useful information Write-Host $ref.Name } However, the script does not output anything, although there certainly are ProjectReference elements in the given csproj file. The following is working: [xml]$csproj = Get-Content MyProject

How to change tab width when converting to JSON in Powershell

匆匆过客 提交于 2019-12-20 12:24:48
问题 I am creating a JSON in Powershell and I want to set a custom tab width when building it (instead of the default 4 white spaces I want to set only 2 white spaces). I am doing this because: the actual JSON (not the one presented in the below sample) is pretty big (100k+ rows) and if not archieved, it's size is pretty big; If I reduce the tab width the size reduction is notable. the actual JSON has a depth of 5+ nodes ! I cannot use -Compress since the JSON needs to be human readable Yes, I

No error when selecting non-existing property

試著忘記壹切 提交于 2019-12-19 09:21:23
问题 I want PowerShell to throw an error when trying to select non-existing properties, but instead I get empty column as output. Example: $ErrorActionPreference=[System.Management.Automation.ActionPreference]::Stop; Set-StrictMode -Version 'Latest' Get-Process *ex* | Select-Object Id,ProcessName,xxx Id ProcessName xxx -- ----------- --- 9084 explorer 11404 procexp I wrote a script that is importing multiple text files by Import-Csv , but headers in those file may change, and I'll end up with