Move a Computer Object to an OU
source: http://technet.microsoft.com/en-us/library/cc731094(WS.10).aspx
Powershell – How to use a config file (ini, conf,…) with a Powershell Script ? Is it possible ?
Hi
Is it possible to use a configuration file with a PowerShell script ?
for example, the configuration file:
#links
link1=http://www.google.com
link2=http://www.apple.com
link3=http://www.microsoft.com
and then call this information in the PS1 script:
start-process iexplore.exe $Link1
thanks in advance for your help!!
Your answers put me on the good track and I found this
SETTINGS.TXT
#from http://tlingenf.spaces.live.com/blog/cns!B1B09F516B5BAEBF!213.entry
#
[General]
MySetting1=value
[Locations]
InputFile="C:\Users.txt"
OutputFile="C:\output.log"
[Other]
WaitForTime=20
VerboseLogging=True
POWERSHELL COMMAND
#from http://tlingenf.spaces.live.com/blog/cns!B1B09F516B5BAEBF!213.entry
#
Get-Content "C:\settings.txt" | foreach-object -begin {$h=@{}} -process { $k = [regex]::split($_,'='); if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) { $h.Add($k[0], $k[1]) } }
then
After executing the code snippet, a variable ($h) will contain the values in a HashTable.
Name Value
---- -----
MySetting1 value
VerboseLogging True
WaitForTime 20
OutputFile "C:\output.log"
InputFile "C:\Users.txt"
*To get an item from the table use the command $h.Get_Item(“MySetting1”).*
Powershell – Finding Old Files
source:http://powershell.com/cs/blogs/tips/archive/2008/11/20/finding-old-files.aspx
filter FileAge($days) { if ( ($_.CreationTime -le (Get-Date).AddDays($days * -1) )) { $_ } }
Pipe the result of a Dir into FileAge filter, and it will only let those files pass that are at least the specified number of days old. The following line finds all PowerShell Script files in your personal folder that are at least 10 days old:
Dir $home\*.ps1 | FileAge 10
You could easily delete or backup the resulting files like this:
Dir $home\*.ps1 | FileAge 10 | Del -WhatIf
Powershell – List Compressed Files/Folders
Source: http://stackoverflow.com/questions/1500114/powershell-wmi-and-compressed-files-folders
Powershell, WMI and compressed files/folders
I need to generate a script that will help me in getting a list of compressed files/folders (not zip files, but Windows compressed files) on a range of Windows 2003 servers. I have a client pc connected to the target servers and have access on a administrator role basis. My thoughts was to create a Powershell script to handle this problem using WMI or something else? But I’m kind of lost on the possibilities in the WMI world. Any hints/tips are appreciated.
Cheers
$computers = 'server1', 'server2', 'server3'
$compressed = Invoke-Command $computers {Get-ChildItem C:\ -r -force -ea 0 |
Where {$_.Attributes -band [IO.FileAttributes]::Compressed}}
Note that each file and dir object stored in $compressed will have an additional property PSComputerName that identifies which computer the deserialized object came from.
Alternatively, if you don’t have PowerShell 2.0 you could access the servers via a share e.g.:
$sharePaths = '\\server1\C$', '\\server2\C$', '\\server3\C$'
This approach is likely to be slow.
Get-ChildItem $sharePaths -r -force -ea 0 |
Where {$_.Attributes -band [IO.FileAttributes]::Compressed}
Powershell – Get-ClipBoard Set-Clipboard
Source:http://stackoverflow.com/questions/1567112/convert-keith-hills-powershell-get-clipboard-and-set-clipboard-to-a-psm1-script
function Get-ClipBoard { Add-Type -AssemblyName System.Windows.Forms $tb = New-Object System.Windows.Forms.TextBox $tb.Multiline = $true $tb.Paste() $tb.Text } function Set-ClipBoard($text) { Add-Type -AssemblyName System.Windows.Forms $tb = New-Object System.Windows.Forms.TextBox $tb.Multiline = $true $tb.Text = $text $tb.SelectAll() $tb.Copy() }