powershell-3.0

powershell XLS to CSV conversion issue

天大地大妈咪最大 提交于 2019-12-12 03:23:22
问题 I am running below code with to convert XLS to CSV but getting strange error. Can someone point me to right direction as to what can be causing this issue? I am using powershell v3.0. not sure what I am missing here. PARAM ( [parameter(Mandatory = $true)] [string] $excelFilePath = $(throw "Must give a valid Excel (*.xls) file path.") , [parameter(Mandatory = $true)] [int] $leadingRowsToDelete = $(throw "Must specify how many leading rows to delete.") , [parameter(Mandatory = $false)] [string]

Copy multiple files to multiple destination based on text file

被刻印的时光 ゝ 提交于 2019-12-12 03:15:25
问题 I want to copy list of files specified in text file to list of destination by creating directory. I have one Excel file in which there are 2 columns, source and destination, each source has a destination. Example Source: \\10.0.0.1\share\abd.nsf \\20.0.0.1\share\red.nsf Example Dest: \\10.0.0.2\share\abd\ \\10.0.0.2\share\red\ Currently I am using below code, but involves n number of lines so it is tedious. copy-item "\\10.0.0.1\share\abd.nsf" -destination (New-item "\\10.0.0.2\share\abd\"

Any UI automation cmdlet is planned in Powershell V3.0

被刻印的时光 ゝ 提交于 2019-12-12 03:05:48
问题 I have searched to find way to automate GUI using powershell and come across with some good online sources. But they are all using custom cmdlet. As new version of powershell is in progress, Is there any new cmdlet are availed for GUI automation? 回答1: Don't think there will be anything specifically for UI automation. I made a blog post with all of the new commands in the Windows 8 developer preview. Nothing for UI automation. You can download the current version CTP 2 here and check it out.

Powershell split string on multiple conditions

心不动则不痛 提交于 2019-12-12 02:59:52
问题 I have a csv file where I am extracting a first and last name from a column, to seperate them in their own columns. So given the string: 'John Doe - Generic- Random' I would use the split(" ") to extract the first and last name $string = 'John Doe - Generic- Random' $firstName = $string.split(" ")[0] $lastName = $string.split(" ")[1] First Issue I found an issue where after the last name, sometimes the string does not have a space. For example $string = 'John Doe-Generic-Random' How would I

Powershell - how to handle non timestamped log file entries, including blank lines

混江龙づ霸主 提交于 2019-12-12 02:17:00
问题 I asked a question about how to extract data from a log file based on a start and end timestamp, recently which I got a great and quick answer for, see this question / post for details. Powershell - How to select a block of text from a text based log file that has a time stamp in the log file entry However, I now find I have an issue in what I am trying to acheive as the log files I am handling / querying do not have a time stamp entry on every line, and in fact some lines are blank and there

Pinging an array of ip addresses concurrently in PowerShell

廉价感情. 提交于 2019-12-12 01:59:23
问题 I have an array of objects with properties "IP" for storing an ip address and "LastAlive" for storing the date that the server last responded to a ping. In order to fill the LastAlive properties I use the following function: function Update-AliveStatus ($nodes) { foreach ($node in $nodes) { $alive = Test-Connection $node.IP -Quiet -Count 2 if ($alive -eq $true) { $node.LastAlive = (Get-Date) } } return $nodes } This works fine unless the list of IPs is long, in which case it takes ages to

Filewatcher to unzip and process when event (.zip) is detected

删除回忆录丶 提交于 2019-12-12 01:37:06
问题 I want to create a filewatcher and do the below flow using PowerShell: Watch for file in folderA (.zip) → move the file to folderB as (.zip) → unzip the moved file in folderC (with same name) → and trigger a batch file → do the same for more incoming .zip files. I checked a related question to this in StackOverflow but I need some more help. My PowerShell script is as below (I am using PowerShell ISE): while ($true) { $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "D:

How to store data from foreach function in HTML file in powershell and get Physicall ram

不羁岁月 提交于 2019-12-11 23:57:34
问题 I have written a for each file which stores the BIOS information of the systems in a network and the result is being displayed on my console but I want them to be in a HTML file in an order. Code: $arrComputers = get-Content -Path "C:\Computers.txt" foreach ($strComputer in $arrComputers) { $colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" ` -computername $strComputer foreach ($objItem in $colItems) { write-host "Computer Name: " $strComputer write-host "BIOS Version: "

Need Help running a batch invisibly from another batch

百般思念 提交于 2019-12-11 20:21:31
问题 I have A batch file named x.bat, i need it to run y.bat invisibly This is x.bat @ECHO off echo CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False>invisible.vbs wscript.exe invisible.vbs y.bat y.bat @ECHO off dir>good.txt pause When i run x.bat it is creating invisible.vbs but it is not opening y.bat invisibly How to overcome this problem 回答1: Solution 1: Modify your file. Save this one line of text as file invisible.vbs : CreateObject("Wscript.Shell").Run """" &

Writing tests for PowerShell functions

筅森魡賤 提交于 2019-12-11 19:13:10
问题 I have the following function (the function is an auxiliary function of an another function and it works correctly): function Get-UserManager { [CmdletBinding()] param ( [pscredential] $credential, [ValidateSet('ID')][string]$searchType, [string]$searchString, ) try { $reply = Invoke-RestMethod -Method Get -Uri $full_uri -Credentia $cred } catch { Write-Verbose "Couldn't connect to the End Point" Write-Debug "$($_.Exception)" return $userListObject } $reply.elements | ForEach-Object { return