powershell-2.0

File Output in Powershell without Extension

送分小仙女□ 提交于 2019-12-10 01:31:42
问题 Here is what I have so far: Get-ChildItem "C:\Folder" | Foreach-Object {$_.Name} > C:\Folder\File.txt When you open the output from above, File.txt, you see this: file1.txt file2.mpg file3.avi file4.txt How do I get the output so it drops the extension and only shows this: file1 file2 file3 file4 Thanks in advance! EDIT Figured it out with the help of the fellows below me. I ended up using: Get-ChildItem "C:\Folder" | Foreach-Object {$_.BaseName} > C:\Folder\File.txt 回答1: Get-ChildItem "C:

How to verify whether the share has write access?

一曲冷凌霜 提交于 2019-12-09 22:35:22
问题 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

Detect If IPv6 is Enabled on Windows Machines

99封情书 提交于 2019-12-09 19:39:59
问题 I am writing a powershell script that will act as a build compliance test for our servers. One of the things I need to do is detect if IPv6 networking has been disabled. WMI indicates that this information can be found in the IPAddress Property of Win32_NetworkAdapterConfiguration but can be both IPv6 or IPv4. This does not give me a "yes/no" answer I am hoping to find. Other caveats are that I would prefer not to scrape the details by accessing the registry directly, nor scrape from the

Launch Elevated CMD.exe from Powershell

一曲冷凌霜 提交于 2019-12-09 19:00:25
问题 I am trying to launch an elevated CMD window from PowerShell but I am running into some issues. Below is the Code I have now. There is an admin account on the machine that has the username of "test" and a Password of "test" $username = "test" $password = ConvertTo-SecureString "test" -AsPlainText -Force $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password Start-Process "cmd.exe" -Credential $cred This is all working fine for running an

Check-Out files from TFS 2010 with powershell

别来无恙 提交于 2019-12-09 17:00:55
问题 I only want to check out a path with powershell and also check in this path one minute later at Team Foundation Server. How can i do this? I have installed the tfs power tools at my server. 回答1: You don't need the power tools. Just use the tf.exe command line util that comes with Visual Studio with TFS Team Explorer. tf edit <file> /noprompt to check out and tf checkin <file> /comment:$comment /noprompt to check in. Look at the command line usage on tf.exe for more info tf /? and tf checkin /

Exporting Collection of Hashtable data to CSV

孤街醉人 提交于 2019-12-09 13:36:27
问题 I am trying to export to CSV the name/value pairs of a collection hashtable items. The I have not found the correct syntax for the select-object portion of the code. I would the CSV file to have columes for Url and Owner. Thanks for the help [System.Collections.ArrayList]$collection = New-Object System.Collections.ArrayList($null) $SiteInfo = @{}; $SiteInfo.Url = "http://some.url.com"; $SiteInfo.Owner = "Joe Smith"; $collection.Add($SiteInfo); $SiteInfo.Url = "http://another.url.com";

How to extract data from a text file using R or PowerShell?

ぃ、小莉子 提交于 2019-12-09 12:48:27
问题 I have a text file containing data like this: This is just text ------------------------------- Username: SOMETHI C: [Text] Account: DFAG Finish time: 1-JAN-2011 00:31:58.91 Process ID: 2028aaB Start time: 31-DEC-2010 20:27:15.30 This is just text ------------------------------- Username: SOMEGG C: [Text] Account: DFAG Finish time: 1-JAN-2011 00:31:58.91 Process ID: 20dd33DB Start time: 12-DEC-2010 20:27:15.30 This is just text ------------------------------- Username: SOMEYY C: [Text]

powershell v2 remoting - How do you enable unencrypted traffic

瘦欲@ 提交于 2019-12-09 07:33:11
问题 I'm writing a powershell v2 script that I'd like to run against a remote server. When I run it, I get the error : Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration. Change the client configurati on and try the request again. For more information, see the about_ Remote_Troubleshooting Help topic. I looked at the online help for about _ Remote_Troubleshooting,

Powershell in a batch file - How do you escape metacharacters?

北城以北 提交于 2019-12-09 06:27:40
问题 Running Windows 7, when I copy a file to an external disk, during a routine file backup , I use Powershell v2 (run from a batch file ) to re-create on the copy file all the timestamps of the original file. The following code works successfully in most cases, but not always:- SET file=%1 SET dest=E:\ COPY /V /Y %file% "%dest%" SetLocal EnableDelayedExpansion FOR /F "usebackq delims==" %%A IN ('%file%') DO ( SET fpath=%%~dpA SET fname=%%~nxA ) PowerShell.exe (Get-Item \"%dest%\%fname%\")

PowerShell Create Folder on Remote Server

醉酒当歌 提交于 2019-12-09 05:32:48
问题 The following script does not add a folder to my remote server. Instead it places the folder on My machine! Why does it do it? What is the proper syntax to make it add it? $setupFolder = "c:\SetupSoftwareAndFiles" $stageSrvrs | ForEach-Object { Write-Host "Opening Session on $_" Enter-PSSession $_ Write-Host "Creating SetupSoftwareAndFiles Folder" New-Item -Path $setupFolder -type directory -Force Write-Host "Exiting Session" Exit-PSSession } 回答1: Enter-PSSession can be used only in