powershell-3.0

PowerShell script to move files and folders including subfolders from one location to another older than x days

痞子三分冷 提交于 2019-12-05 12:03:59
问题 I developed a PowerShell script, and it's working absolutely fine. The only challenge is the files in the subfolders are not getting moved to the destination. get-childitem -Path "\\servername\location" | where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} | move-item -destination "C:\Dumps" I am unable to customize the script further. 回答1: Use the -Recurse option on the Get-ChildItem command to get through to the files in the sub folders and then move each individually by piping the

Getting a dynamic database parameter on a SQL server

故事扮演 提交于 2019-12-05 10:00:41
问题 I'm creating a PS function with 2 parameters: $server & $database . I need the $database parameter to be auto-populated (dynamic validation set), depending on the first parameter ($server) I got most of the code from here However it is NOT working. What am I doing wrong here? Any insight is greatly appreciated. Thank you. function Get-databases { [CmdletBinding()] Param( # Any other parameters can go here [Parameter(Mandatory)][string] $Server ) DynamicParam { # Set the dynamic parameters'

When a commandlet accepts pipeline input, what is the difference between ByPropertyName and ByValue?

痴心易碎 提交于 2019-12-05 09:21:59
Some PowerShell commandlets accept pipeline input ByProperyName, some do it ByValue, others do it for both. What does this mean? How does it impact our PowerShell scripts? The ValueFromPipeline parameter attribute will map the parameter value to whatever object type is passed in from the pipeline. If you use the ValueFromPipelineByPropertyName parameter attribute , then a specific property will be used from the objects that are piped into the command+parameter. ValueFromPipeline Example Get-Process | Stop-Process; # Stop-Process expects to receive a Process object <# -InputObject <Process[]>

Change the current culture of a Powershell session, v3.0+ specific

為{幸葍}努か 提交于 2019-12-05 02:01:25
问题 I want to change the culture of accepted data and errors in my current interactive Powershell session. I am aware of this question powershell : changing the culture of current session and of this question Changing current culture on SuperUser. The main problem that it doesn't work with Powershell 3.0 and 4.0. PS C:\users\me\Documents> [system.threading.thread]::currentthread.currentculture LCID Name DisplayName ---- ---- ----------- 1049 ru-RU Русский (Россия) PS C:\users\me\Documents>

Powershell: Determine if a process is 32 or 64 bit

会有一股神秘感。 提交于 2019-12-05 00:39:41
问题 Is there a way to determine if a given process ID is for a 32 or a 64 bit process? I'm using Powershell v3.0 回答1: Try this: Add-Type -MemberDefinition @' [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWow64Process( [In] System.IntPtr hProcess, [Out, MarshalAs(UnmanagedType.Bool)] out bool wow64Process); '@ -Name NativeMethods -Namespace Kernel32 Get-Process -Id $id | Foreach {

Update Outlook inbox folder

旧时模样 提交于 2019-12-04 21:55:59
I would like to update (sync) the inbox folder (send/receive) before running this PowerShell script that gets the e-mails, but I don't know how. Is there a way to do this from powershell? $matchString= "support@blabla.com"; $olFolderInbox = 6 $outlook = New-Object -COM Outlook.Application; $mapi = $outlook.GetNameSpace("MAPI"); $inbox = $mapi.GetDefaultFolder($olFolderInbox) $inbox.Items | where { $_.SenderEmailAddress -match $matchString } | Select SenderEmailAddress,to,subject | Format-Table -AutoSize This is how you do that: $mapi.SendAndReceive($false) Also, for me I needed to use the

Convert UNC Path to NTFS local path

余生长醉 提交于 2019-12-04 21:09:35
I have a problem converting UNC location to local drive in powershell. So my code basically takes input from user as read Host as UNC path for a DB Backup location. The location could be like this \\ServerName\m$\SQLBackups\123 . It then prompts where the backup is being copied from. Again this is a UNC path such as \\ServerName\g$\SQLRestores\444\Filename.bak . I need to convert both paths to their local path so that it reads m:\sqldbackups\123 and g:\sqlrestores\444\Filename.bak . Here is my code below and I have added a comment of what I want the final output to be. $BackupPath = "\

How to specify application pool identity user and password from PowerShell

佐手、 提交于 2019-12-04 15:21:12
问题 I have been having lots of difficulty automating the setup of a Web application and configuring IIS appropriately with the Application Pool Identity. I am doing this in a Web application deployment script written in PowerShell. My requirement is that I need my PowerShell script to set the application pool identity user to a specific service account mydomain\svcuser and password. Here is the sample code: $pool = New-Item "IIS:\AppPools\MyAppPool" -Force $svcuser = "mydomain\svcuser" $pool

Change the current culture of a Powershell session, v3.0+ specific

99封情书 提交于 2019-12-04 15:08:53
I want to change the culture of accepted data and errors in my current interactive Powershell session. I am aware of this question powershell : changing the culture of current session and of this question Changing current culture on SuperUser. The main problem that it doesn't work with Powershell 3.0 and 4.0. PS C:\users\me\Documents> [system.threading.thread]::currentthread.currentculture LCID Name DisplayName ---- ---- ----------- 1049 ru-RU Русский (Россия) PS C:\users\me\Documents> [system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-US" PS C:\users

PowerShell Get-DiskUsage CmdLet: how to list from a different drive/directory?

流过昼夜 提交于 2019-12-04 14:40:33
问题 I'm a relative newbie on PowerShell, wanted to know a bit more about functions, CmdLet and human readable values. Usually for learning new things, looking at what others do works well. So I went looking and bumped into the source for a Get-DiskUsage CmdLet. I can . source this into PowerShell, then call the function. Somehow, it always uses the current directory for getting the results no matter how I call it. What am I missing that it will not take the given -Path parameter? PS D:\bin> . .