powershell-2.0

Alternative to Append export-csv powershell

删除回忆录丶 提交于 2019-12-02 22:03:35
问题 I add user logon and logout tracking script I found that some computers do not export csv as they have powershell 2.0 because append is not supported is there any alternative? $ErrorActionPreference = 'Continue' ####**** Tracking user logon *****##### $username = $env:USERNAME $computername = $env:COMPUTERNAME $ipv4 = Test-Connection -ComputerName (hostname) -Count 1 | foreach { $_.ipv4address } $ipv6 = Test-Connection -ComputerName (hostname) -Count 1 | foreach { $_.ipv6address } $timeformat

Use PowerShell to generate a list of files and directories

醉酒当歌 提交于 2019-12-02 20:30:07
I'm writing a PowerShell script to make several directories and copy a bunch of files together to "compile" some technical documentation. I'd like to generate a manifest of the files and directories as part of the readme file, and I'd like PowerShell to do this, since I'm already working in PowerShell to do the "compiling". I've done some searching already, and it seems that I need to use the cmdlet "Get-ChildItem", but it's giving me too much data, and I'm not clear on how to format and prune out what I don't want to get my desired results. I would like an output similar to this: Directory

Changing the physical path of an IIS website on a remote machine via Powershell

假装没事ソ 提交于 2019-12-02 20:22:15
I'm currently working on a deployment script that will take my site, export it from svn, remove any testing files etc in it, minify the javascript/css, copy the code to a remote web server, and then switch the physical path of the existing site to the new directory. So far I have everything working except for switching the physical directory in IIS. $IIsServer = Get-WmiObject Site -Namespace "root/WebAdministration" -ComputerName $serverIP -Credential $credentials -Authentication PacketPrivacy $site = $IIsServer | Where-Object {$_.Name -eq $siteName} When I look into the values I have I cant

GetType used in PowerShell, difference between variables

浪子不回头ぞ 提交于 2019-12-02 17:48:47
What is the difference between variables $a and $b ? $a = (Get-Date).DayOfWeek $b = Get-Date | Select-Object DayOfWeek I tried to check $a.GetType $b.GetType MemberType : Method OverloadDefinitions : {type GetType()} TypeNameOfValue : System.Management.Automation.PSMethod Value : type GetType() Name : GetType IsInstance : True MemberType : Method OverloadDefinitions : {type GetType()} TypeNameOfValue : System.Management.Automation.PSMethod Value : type GetType() Name : GetType IsInstance : True But there seems to be no difference although the output of these variables looks different. Cédric

Powershell variable export-CSV cache?

为君一笑 提交于 2019-12-02 17:30:34
问题 I am working on a script by Richard L. Mueller (http://www.rlmueller.net/PowerShell/PSLastLogon.txt) Trap {"Error: $_"; Break;} $D = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $Domain = [ADSI]"LDAP://$D" $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.PageSize = 200 $Searcher.SearchScope = "subtree" $Searcher.Filter = "(&(objectCategory=person)(objectClass=user))" $Searcher.PropertiesToLoad.Add("samAccountName") > $Null $Searcher

Export function

假装没事ソ 提交于 2019-12-02 15:56:15
问题 I am trying to create a function in which a user has to give a filename that can not containt an empty string. Besides that, the string can not contain a dot. When I run this function, I keep looping when I enter "test" for example. Any idea as to why? function Export-Output { do { $exportInvoke = Read-Host "Do you want to export this output to a new .txt file? [Y/N]" } until ($exportInvoke -eq "Y" -or "N") if ($exportInvoke -eq "Y") { do { $script:newLog = Read-Host "Please enter a filename!

How to find the Windows version from the PowerShell command line

你说的曾经没有我的故事 提交于 2019-12-02 14:02:29
How do I find which Windows version I'm using? I'm using PowerShell 2.0 and tried: PS C:\> ver The term 'ver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify tha t the path is correct and try again. At line:1 char:4 + ver <<<< + CategoryInfo : ObjectNotFound: (ver:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException How do I do this? Jeff Mercado Since you have access to the .NET library, you could access the OSVersion property of the System.Environment

How to embed Images in a powershell email using MailMessage

喜夏-厌秋 提交于 2019-12-02 13:42:59
I have an email that works from PS. What I have been trying to do is include images embedded in the email (not attachments). Below is what I have so far: function Email { $smtpServer = {smtp server} $smtpFrom = {email from} $smtpTo = {email to} $messageSubject = "test" $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto $message.Subject = $messageSubject $message.IsBodyHTML = $true $credentials=new-object system.net.networkcredential({smtpUsername},{smtpPassword}) # $message.Body = Get-Content "D:\Program Files\CymbaTech_FBNC_AM\CTDataLoader\data\TestBody.html" # The line

Mouse event don't work after first timer Tick

▼魔方 西西 提交于 2019-12-02 13:40:30
I'm using powershell to develop a little tool with graphic interface and I'm going crazy with this issue... For example: I have a label on a form that display "real-time" status of a ping. In the same time, if you click on the label, a popup message is displayed. function GoogleStatus ($Label) { $Google = "www.google.com" If (Test-Connection -ComputerName $Google -Count 1 -Quiet) {Label.Text = "Yes"} else {Label.Text = "No"} } function HelloMsg { [System.Windows.Forms.MessageBox]::Show("Hello","Funny Window",0,32) } [void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

Conditional replace in XML files

青春壹個敷衍的年華 提交于 2019-12-02 12:00:14
问题 I'm replacing a text in XML files recursively using PowerShell. The script is working fine in replacing. However the XML files also have file paths which should not be replaced. This is the script currently being used if ( $content -match ' web site | web-site ' ) { $content -replace ' web site ',' New Site ' -replace ' web-site ',' New Site ' | Out-File $file.FullName -Encoding utf8 For example if the XML file has <title>web site</title> <subtitle>web-site</subtitle> <path>c:/web site