powershell-4.0

PowerShell File rename

走远了吗. 提交于 2020-07-11 04:13:08
问题 How to ignore file rename if the filename already contains string during file rename process. My example: Get-ChildItem "D:\Shares\WinCAP Data\DAYPROT\OFS-222_2\*.csv" | Rename-Item -NewName { $_.Name -replace "\.csv", "TC.csv" } I would like to rename just files without string "TC" in filename - for example: abc.csv to rename defTC.csv do not want to rename 回答1: You could filter off the files which don't require the rename with a regex: ?{!($_.fullname -match "TC\.csv")} So, for your example

PowerShell File rename

老子叫甜甜 提交于 2020-07-11 04:12:51
问题 How to ignore file rename if the filename already contains string during file rename process. My example: Get-ChildItem "D:\Shares\WinCAP Data\DAYPROT\OFS-222_2\*.csv" | Rename-Item -NewName { $_.Name -replace "\.csv", "TC.csv" } I would like to rename just files without string "TC" in filename - for example: abc.csv to rename defTC.csv do not want to rename 回答1: You could filter off the files which don't require the rename with a regex: ?{!($_.fullname -match "TC\.csv")} So, for your example

Powershell to get AD user disabled in the past 6 months?

僤鯓⒐⒋嵵緔 提交于 2020-06-17 09:59:26
问题 How to get the AD user that was disabled in the past 6 months and also the time stamp when it was disabled in dd/MM/yyyy format as.CSV file? Like using this Powershell https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-aduser?view=win10-ps ? $paramhash=@{ UsersOnly = $True AccountDisabled = $True SearchBase = "OU=Employees,DC=globomantics,dc=local" } Search-ADAccount @paramHash | Get-ADuser -Properties Description,Department,Title,LastLogonDate,WhenChanged | sort

Powershell rename the files from a directory

假装没事ソ 提交于 2020-05-28 11:51:28
问题 $ht = @{} $o = new-object PSObject -property @{ from = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\LAA" to = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\destinatie" } $ht.Add($o.from, $o) $o = new-object PSObject -property @{ from = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\LBB" to = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\destinatie" } $ht.Add($o.from, $o) $o = new-object PSObject -property @{ from = "C:\Users\nicolae.calimanu\Documents

Powershell rename the files from a directory

ぃ、小莉子 提交于 2020-05-28 11:51:05
问题 $ht = @{} $o = new-object PSObject -property @{ from = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\LAA" to = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\destinatie" } $ht.Add($o.from, $o) $o = new-object PSObject -property @{ from = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\LBB" to = "C:\Users\nicolae.calimanu\Documents\scripturi copiere\destinatie" } $ht.Add($o.from, $o) $o = new-object PSObject -property @{ from = "C:\Users\nicolae.calimanu\Documents

Recursively search a directory for files whose content matches a regex and collect the paths of matching files in an array

霸气de小男生 提交于 2020-05-28 06:37:26
问题 $locations = Get-ChildItem $readLoc -recurse | ? {!$_.psiscontainer} | select-object name | %{$e = $_.name; get-content $e} $array = @() for($i = 0; $i -lt $locations.length; $i++){ #if($locations.name[$i].length -eq "9"){ $paths = Resolve-Path $locations.fullname[$i] $paths.path get-content $locations.name[$i] #$array += $paths.path #} } I need to iterate through each file in the file system and open each file. I am checking to see if a string within the file matches a regular expression and