I have been searching this for long time. Now i have found out
dir -recurse | Where-Object { $_.PSIsContainer } | Get-Acl
dir -recurse - Is to get all folders and subfolders
$_.PSIsContainer - Is to check whether the object is a directory or a file
Get-ACL - to get ACLs for folders
Welcome to my Scripting page. This blog has ready to use VBScript and Powershell scripts either written or collected from various websites around the web
Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts
Thursday, July 7, 2011
Sunday, October 17, 2010
Powershell - Get windows service status on a remote computer
Command to get the remote server service status through powershell is listed below
Get-service -computername "Servername" -displayname "servicename"
Get-service -computername "Servername" -displayname "servicename"
Saturday, October 16, 2010
Powershell to get server uptime
I dont remember from which site i got the below script but it is very useful in my day to day admin life
$wmi=Get-WmiObject -class Win32_OperatingSystem -computer "Computername"
$LBTime=$wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
Write-host $server “Uptime: ” $uptime.days “Days” $uptime.hours “Hours” $uptime.minutes “Minutes” $uptime.seconds “Seconds”
Get-WmiObject -class Win32_OperatingSystem
This will invoke the Operating System wmi object
ConvertToDateTime
Will convert the output to human readable form
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
This will compare the output time with the current time and store the result to the string as object
$wmi=Get-WmiObject -class Win32_OperatingSystem -computer "Computername"
$LBTime=$wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
Write-host $server “Uptime: ” $uptime.days “Days” $uptime.hours “Hours” $uptime.minutes “Minutes” $uptime.seconds “Seconds”
Get-WmiObject -class Win32_OperatingSystem
This will invoke the Operating System wmi object
ConvertToDateTime
Will convert the output to human readable form
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
This will compare the output time with the current time and store the result to the string as object
Powershell - Search a string inside a text file
Get-Content cmd let will allow reading content from a text file and the following piped cmdlet can be used to search a string inside the text file given as input
(Get-Content "Full path of the text file") | ? {$_ -match 'searchstring''}
(Get-Content "Full path of the text file") | ? {$_ -match 'searchstring''}
Uninstalling Previous Versions of PowerShell
Uninstalling Previous Versions of PowerShell
PowerShell v1 RTM shipped as updates to the OS. Therefore, it will show up only in the updates section. To look for previous versions, do the following:
On Windows XP/Server 2003:
· Go to Add/Remove Programs
· Select Show Updates
· Look for any of the following KB numbers which indicate earlier versions of PowerShell
o KB926139 – Windows PowerShell v1.0 RTM – English Language Version
o KB926140 – Windows PowerShell v1.0 RTM – Localized Installation Package
o KB926141 – Windows PowerShell v1.0 RTM – MUI pack
o KB925228 – Windows PowerShell v1.0 RC2
· Versions of V1 prior to RC2 are MSI based installations and they will appear as Windows PowerShell in the programs list
· Uninstall the previous version that's installed
On Windows Vista:
· Go to Programs and Features
· Click on View Installed Updates
· Look for any of the following KB numbers which indicate earlier versions of PowerShell
o KB928439 – Windows PowerShell 1.0 RTM
o KB923569 – Windows PowerShell 1.0 RC2
· Version of V1 prior to RC2 are MSI based installations and they will appear as Windows PowerShell in the installed programs list
· Uninstall the previous version that's installed
On Windows Server 2008:
· Launch Server Manager
· Go to Features
· Click on Uninstall Features. This brings up a list of installed features to choose from
· Select Windows PowerShell and uninstall
Friday, September 24, 2010
Powershell - Get Powershell version
To get the Powershell version Get-Host cmdlet is used. The following example will show this
Get-host | Select version
Powershell - Retrieve hotfixes installed on a local or remote computer
To Retrieve hotfix in a computer on a powershell 2.0 version
Wednesday, September 22, 2010
Powershell - Setting default printer in the Desktop
In Windows 7 setting a default printer through powershell cmdlets is a easier task when compared to VBscript. It can achieved through fewer commands. The commands and their description are given below
CMDLETS
$Printer = Get-WmiObject win32_printer | where {$_.name -match "XPS"}
$Printer.SetDefaultPrinter()
"XPS" in the command can be replaced by your printer name , unique word which will exactly point your printer can be mentioned within the quotations
win32_Printer
This WMI class will hold all the printer information in your computer
SetDefaultPrinter()
This method inside Win32_Printer will set the selected printer as a default printer
Tuesday, September 21, 2010
Powershell - How to check service packs on computers
Service pack of the operating system can found by calling the wmi object win32_operatingsystem. Following commands will enumerate the service pack
$SP = gwmi win32_operatingsystem
$SP.serivepackmajoreversion
$SP = gwmi win32_operatingsystem
$SP.serivepackmajoreversion
Monday, September 20, 2010
Install and Configure Windows PowerShell
1. Install the Windows Management Framework
- Download and install the Windows Management Framework. Choose the package that includes Windows PowerShell v2 and WinRM 2.0, and that applies to your operating system, system architecture, and language.
Note If your local computer is protected by a Microsoft Internet Security and Acceleration (ISA) server, see Windows PowerShell: FAQs for Administrators.
2. Verify that Windows PowerShell can run scripts
- Click Start > All Programs > Accessories > Windows PowerShell.
- Do one of the following to open Windows PowerShell:
- If you're running Windows Vista, Windows 7, or Windows Server 2008 R2, right-click Windows PowerShell and select Run as administrator. If you get a user account control prompt that asks if you would like to continue, respond Continue.
- If you're running Windows XP or Windows Server 2003, click Windows PowerShell.
- Run the following command:Get-ExecutionPolicy
- If the value returned is anything other than
RemoteSigned, you need to change the value toRemoteSigned.
Note When you set the script execution policy toRemoteSigned, you can only run scripts that you create on your computer or scripts that are signed by a trusted source.
Thursday, September 16, 2010
The term is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
Subscribe to:
Posts (Atom)