powershell-2.0

PowerShell - Decode System.Security.SecureString to readable password

℡╲_俬逩灬. 提交于 2019-12-17 06:46:11
问题 I want to decode the password from a System.Security.SecureString to a readable password. $password = convertto-securestring "TestPassword" -asplaintext -force $credentials = New-Object System.Net.NetworkCredential("TestUsername", $password, "TestDomain") This code part works fine, I can use the $credentials object. But later in my code I need the password in a readable format. Because a methode needs the password in readable string. So I must decode the password back. How it is possible to

Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait

孤人 提交于 2019-12-17 06:33:29
问题 I'm trying to run a program from PowerShell, wait for the exit, then get access to the ExitCode, but I am not having much luck. I don't want to use -Wait with Start-Process, as I need some processing to carry on in the background. Here's a simplified test script: cd "C:\Windows" # ExitCode is available when using -Wait... Write-Host "Starting Notepad with -Wait - return code will be available" $process = (Start-Process -FilePath "notepad.exe" -PassThru -Wait) Write-Host "Process finished with

How to speed up Powershell Get-Childitem over UNC

醉酒当歌 提交于 2019-12-17 06:11:20
问题 DIR or GCI is slow in Powershell, but fast in CMD. Is there any way to speed this up? In CMD.exe, after a sub-second delay, this responds as fast as the CMD window can keep up dir \\remote-server.domain.com\share\folder\file*.* In Powershell (v2), after a 40+ second delay, this responds with a noticable slowness (maybe 3-4 lines per second) gci \\remote-server.domain.com\share\folder\file*.* I'm trying to scan logs on a remote server, so maybe there's a faster approach. get-childitem \\$s

How to speed up Powershell Get-Childitem over UNC

随声附和 提交于 2019-12-17 06:11:11
问题 DIR or GCI is slow in Powershell, but fast in CMD. Is there any way to speed this up? In CMD.exe, after a sub-second delay, this responds as fast as the CMD window can keep up dir \\remote-server.domain.com\share\folder\file*.* In Powershell (v2), after a 40+ second delay, this responds with a noticable slowness (maybe 3-4 lines per second) gci \\remote-server.domain.com\share\folder\file*.* I'm trying to scan logs on a remote server, so maybe there's a faster approach. get-childitem \\$s

How do I concatenate two text files in PowerShell?

穿精又带淫゛_ 提交于 2019-12-17 05:40:30
问题 I am trying to replicate the functionality of the cat command in Unix. I would like to avoid solutions where I explicitly read both files into variables, concatenate the variables together, and then write out the concatenated variable. 回答1: You can simply use cat example1.txt, example2.txt | sc examples.txt . You can surely concatenate more than two files with this style, too. Plus, if the files are named similarly, you can use: cat example*.txt | sc allexamples.txt The cat is an alias for

PowerShell 2.0 ConvertFrom-Json and ConvertTo-Json implementation

痞子三分冷 提交于 2019-12-17 05:04:44
问题 I would like to monkeypatch a PowerShell 2.0 environment where the upgrade to 3.0 is not possible at this time. I am looking for a PowerShell 2.0 script implementation of the ConvertFrom-Json cmdlet and ConvertTo-Json cmdlet that are in PowerShell 3.0. I am most interested in the ConvertFrom-Json , but ConvertTo-Json would also be nice. 回答1: function ConvertTo-Json20([object] $item){ add-type -assembly system.web.extensions $ps_js=new-object system.web.script.serialization

scheduling task in windows 2008 with powershell

荒凉一梦 提交于 2019-12-16 18:02:52
问题 i want to schedule task in windows 2008 r2 with powershell. i used $username = "BUILTIN\Users" $TaskName = 'kakaka' $t=1 $TaskRun = "$PSHome\powershell.exe Start-Process -FilePath 'C:\v.exe' -ArgumentList '/a' -Verb runas -WindowStyle Normal" $start = (Get-Date).AddMinutes($t).ToString("HH:mm") schtasks /create /ru $username /tn $Taskname /tr $TaskRun /sc once /st $start /f on using above script i got an error "schtasks.exe : ERROR: The task XML contains a value which is incorrectly formatted

How to verify whether the share has write access?

空扰寡人 提交于 2019-12-14 04:16:30
问题 I am having share with write access. I am writing a powershell script to write a log file in that share. I would like to check the condition whether i am having write access to this share before writing in it. How to check for write access/Full control using powershell? I have tried with Get-ACL cmdlet. $Sharing= GEt-ACL "\\Myshare\foldername If ($Sharing.IsReadOnly) { "REadonly access" , you can't write" } It has Isreadonly property, But is there any way to ensure that the user has

multiple exclude rules in powershell

筅森魡賤 提交于 2019-12-14 03:31:33
问题 I have a requirement to exclude files based on year, country name and last modified date from that particular year and rest files from that particular year and the country moved to an archive folder for an example SS_MM_Master_finland_2018.xlsx last modified date 27/06/2018 19:00. SS_MM_Master_finland_2017.xlsx last modified date 27/06/2017 19:00. in this case, same country and year is different in the file name so that particular year- last modified date would be excluded so both the files

Why I am getting PowerShell Parsing Error?

若如初见. 提交于 2019-12-14 03:16:15
问题 I am new to PowerShell and I am trying to get a script to work to list my parallel ports. I took the PowerShell script from here: On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_ParallelPort") For Each objItem in colItems Wscript.Echo "Availability: " & objItem.Availability For Each strCapability in objItem.Capabilities Wscript