Quantcast
Channel: Windows PowerShell Forum
Viewing all 2562 articles
Browse latest View live

Problem sunning Powershell script as a scheduled task

$
0
0

I'm working on a script to rotate my IIS logs.  The scipt I've written works fine in the shell but when I run it as a scheduled task it fails.

I've cut the script down to only these lines:

Start-Transcript "D:\scheduled_task.log"
Import-Module WebAdministration
$LogfileDirectory = (Get-ItemProperty "IIS:\Sites\Default Web Site").logfile.directory
$LogfileDirectory
Stop-Transcript

And the output of Start-Transcript is:

**********************
Windows PowerShell transcript start
Start time: 20130130192555
Username  : HOSTED\jimho
Machine   : WEB01 (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is D:\scheduled_task.log
Get-ItemProperty : Could not load file or assembly
'Microsoft.PowerShell.Commands.Management' or one of its dependencies. The
system cannot find the file specified.
At D:\Mediclick\eMaterials\Tools\LogArchiverTEST.ps1:5 char:22
+ $LogfileDirectory = (Get-ItemProperty "IIS:\Sites\Default Web
Site").logfile.dir ...
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ItemProperty], FileNotFou
   ndException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS
   hell.Commands.GetItemPropertyCommand
 
**********************
Windows PowerShell transcript end
End time: 20130130192556
**********************

I've set/un-set every option on the General tab of the task properties, I've entered the full path to the powershell exe and the full path to my script is entered in the Add Arguments box.  I've tried appending a couple things (-noprofile, etc.) but still no joy.  This is on Server 2008 R2.

Any ideas?


sortedlist to html

$
0
0

Hello all,

I am new to PS pretty much and setting up some SP detail to be mailed to me.

Everything is working fine but the sortedlist.

This is what i got 

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$services = new-object system.collections.sortedlist 
$servers = (get-spfarm).servers 
foreach ($server in $servers)
{
    foreach($service in $server.serviceinstances)
    {
        if ($service.status = "Online")
        {
            $s = $service.typename
            if ($services.contains($s))
            {
                $serverlist = $services[$s]
                $servername = $server.name
                $services[$s] = "$serverlist - $servername"
            }
            else
            {
                $services[$s] = $server.name
            }
        }
    }
}
$services 

Problem is i looked at google and all that but no idea how to start setting it to | ConvertTo-Html so i can use it in my email ?

Any help would be great 

Thanks 

Move and rename each file and avoid this file next time.

$
0
0

Hello there, can you help me with a little powershell script.

I would like move XML files only to another folder with old name and mark the files at the  end _Copied. Keep .xml extension. And skip this file if find "_Copied" mark.

I've got a batch with findstr and temp, but I would like use and learn a powershell script.

dir /b /a-d %source%\*.xml |findstr /v "Copied.xml" >%temp%\@movelist.tmp
For /F %%f in (%temp%\@movelist.tmp) do rename %source%\%%f %%~nf_Copied.xml

Thank you

Powershell if/else statement

$
0
0

Hi,

I hope this is the correct forum for my question. I am trying to write a script that tells me what the status of a hyper-v integration service is on a VM and then disable the service if it is true. Here is my script so far. I get as far as the if statement but it doesn't go to the else statement.

Currently timesync is set to true.

$timesync = get-vmintegrationservice -vmname <VNname> -name "Time Synchronization"
$status = $timesync.enabled
if ($status -eq "False") {write-host "time service disabled"}
Else {write-host "time is enabled"}

My end script I want it to actually do something like this:

$timesync = get-vmintegrationservice -vmname <VMname> -name "Time Synchronization"
$status = $timesync.enabled
if ($status -eq "False") {write-host "time service disabled"}
ELSE {disable-vmintegrationservice -vmname <VMName>"Time Synchronization"}

Any help with where I am going wrong is greatly appreciated.

Thanks,
Georgi


Georgi

the variable named $profile when used as $profile | select *

$
0
0

How can $profile be a simple string, yet when piped to select be a container for several strings?

Is select-object doing the conversion? 


C:> $profile
C:\Users\Larry\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

C:> $profile.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object


C:> $profile.length
75
C:> $profile | select *


AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.P
                         owerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\Larry\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\Larry\Documents\WindowsPowerShell\Microsoft.P
                         owerShell_profile.ps1
Length                 : 75

C:> ($profile | select *).gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PSCustomObject                           System.Object




Finding files with specific extensions from C drive for a number of servers and returning details in excel.

$
0
0

Hi,

I am looking forward to collect all the files with .BAK extension from the C drive for a number of servers and returning them in excel format. However, I noticed that get-childitem does not have -computername parameter so I am unable to loop through server names. I am a newbie in PS and looking forward to learn more on this. Please find below the script I used, could you please assist in correcting this so that I could collect the information I need.

$erroractionpreference = “SilentlyContinue”

$a = New-Object -comobject Excel.Application

$a.visible = $True

$b = $a.Workbooks.Add()

$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = “Machine Name”

$c.Cells.Item(1,2) = “File Name”

$c.Cells.Item(1,3) = “Directory”

$d = $c.UsedRange

$d.Interior.ColorIndex = 19

$d.Font.ColorIndex = 11

$d.Font.Bold = $True

$d.EntireColumn.AutoFit()

$intRow = 2

$colComputers = get-content "C:\Serverlist.txt"

foreach ($strComputer in $colComputers)

{

$findfiles = get-childitem -recurse -ErrorAction SilentlyContinue C:\|where-object{$_.extension -eq ".BAK"}|select Name,Directory

foreach ($filess in $findfiles)

{

$c.Cells.Item($intRow, 1) = $strComputer.ToUpper()

$c.Cells.Item($intRow, 2) = $filess.Name

$c.Cells.Item($intRow, 3) = $filess.Directory

$intRow = $intRow + 1

}

}

$d.EntireColumn.AutoFit()

cls


MM

Read fails when text contains Ascii 0D

$
0
0

I have a script which is trying to read a text file, but the script does not behave properly. Some of the lines are read as two lines.

Sometimes there is an ASCII 0D Carriage Return embedded in the file's data, causing the Powershell script to behave as if there is an end of line, which is  ASCII 0D0A. How do I tell powershell to use 0D0A as end of line and not just 0D? 

Thanks

foreach($linein get-content$filename)  

Powershell Exchange Command

$
0
0

Hey,

Basically im having an issue with a powershell script im writing to remove users in our company.

the problem is that when my script calls the exchange command I need to wait for it to complete said command to be able to continue, I cannot put a wait in as it could fall over if the command takes longer to execute than the wait.

I was wondering if there is any way whatsoever to not proceed to the next line of the script until the exchange command is fully complete. its a New-MailboxExportRequest and the command im running is:

New-MailboxExportRequest -Mailbox $user -FilePath "$filelocation.pst"

When the command runs it queues it then completes after a bit.

Thanks in advance.


NTFS permissions from a folder structure (and sub-folders)

$
0
0

Hi Guys.

I'm trying to export a list of NTFS permissions from a folder structure (and sub-folders) on several shambolically permissioned Windows 2008 R2 Servers (100 shares) with a view to comparing the logons to new logons, and migrating the data to an entirely new NAS (with an entirely new domain and no old login names or sid history migration). I've been trying to use get-acl with (very!) limited success, but any method or suggestions would be gratefully appreciated,

Ideally I would like to export to a csv, in a horizontal format, with just the folder name/path & the users assigned permissions, for example -

folderpath1, domain\user1, type (allow / deny), inheritance, propagation, rights
folderpath1, domain\user2, type (allow / deny), inheritance, propagation, rights

I only need to report on folders, I don't want to extract file information, and ideally I would only like to extract permissions for the top four folder levels in each share, not sure if that is possible?

I'm not really sure how to factor the permission levels into this export, so guidance would be appreciated on that!

Thank you for taking the time to look!

[Novice] - Obtaining CPU Percent Usage for Specific Process

$
0
0

Greetings,

I'm brand new to PowerShell, and haven't done much scripting period so I apologize for my ignorance on the issue.  I'm trying to solve an issue with a thin-client application that users can access from their Client PC from a Host server.  When the client PC opens this thin-client, an instance of this process is opened on the host server.  

If the Client PC fails to close the thin-client properly, the instance on the host server remains running until it eats up CPU usage enough to where it crashes the server.  To alleviate this, I figured I'd dig into writing a script for automation purposes that would check the specific .exe to see if it's > CPU %, and if true, kill the ID of that particular instance. 

However, I'm having trouble actually determining how to go about pulling the CPU usage for a particular process.  UsingGet-Process doesn't seem to give me the information I need.  Could someone kindly steer me in the correct direction?

Again, I apologize.  Most of my experience in handling such things have been on a UNIX/Linux system (I love how similar PowerShell is for a Linux user by the way!)

Thank you in advance.


SharePoint Require Enterprise Keywords (metadata)

$
0
0

I am looking to see what I need to do to start to build / how to build a PowerShell script.  I have an article on my blog on what I want to do graphically.

http://www.westportpoint.org/Blog/Lists/Posts/Post.aspx?ID=9

I have a SharePoint 2010 SP1 Enterprise Edition CU Dec 2012 and I want to require Enterprise Keywords on Document Libraries.  I am doing it manually on the content types in those libraries but I am sure that there is a way to do so with a PowerShell Script.  I am not a PowerShell person, and I am having trouble figuring out how to "start" to build this.  I don't know if people can assist / point me in the right direction!

I know that I need to set a value to FALSE or TRUE, but I don't know how to find out what the name is for a particular item, such as Content Type.

Thank you!
Matt

run powershell script with parametes from web page

$
0
0

Hi everybody,

I am new to powershell scripting and I would kindly need your support/idea in the following project I would like to build:

I have to create a web page (username and password) which I would use to check the credentials in AD. - If the credentials are valid, then the user will be redirected to another page, fill in a report (attach pictures) and submit them in MS SQL database.

I have a PowerShell script that check the credentials in AD and is working fine.

==================================================

My question: How to transmit the username and the password to the script, run it in background and send the result back to the Web page for further action? I want to use PHP/Apache as Web Server, https.

Your ideas would be much appreciated.

Thanks in advance.

Bogdan

DFSN module (server 2012)

$
0
0

I am using the DFSN module from PowerShell 3 on Server 2012 to manage a DFS Root hosted on a Server 2008 R2 server. I am running into 5 problems I could use some help with:

1) I cannot use the commandlet New-DfsnFolder to created a DFS folder that does not have a targetPath specified.

  • I wish to do this so that I can use DFS to create folders with subfolders that have targets.
  • I know this is possible because I can do it through the GUI, it's documented by Microsoft (http://technet.microsoft.com/en-us/library/cc730736.aspx), and I've seen it in practice.

2) When I create the above mentioned folder through the GUI, an item called ".dfsfolderlink" gets created inside the folder.

  • This item disappears when through the GUI you create a folder with a target inside of the folde.
  • This item will NOT disappear when using the commandlet New-DfsnFolderTarget (or New-DfsnFolder for that matter) to create a folder with a target inside of the folder.
  • This item cannot be deleted by an admin either browsing DFS or the share on the DFS namespace server.

3) I cannot use the commandlets Get, Grant, remove, and revoke-DfsnAccess on the folder without a target that contains folders with targets (as described in 1 above) or even one that contains no folders/targets.

  • This is a problem because I wish to hide the folder if users do not have permission to view folders with targets that are subfolders of that middle folder.
  • If it were an option to set permission, I would do so using groups / nesting.

4) I cannot use the commandlets Grant-DfsnAccess on any folder/target and have that entry (which is retrievble via Get-DfsnAccess) actually cause people without permission to not see it NOR will that entry show in the DFS Management GUI.

  • The fact that it won't show in the GUI is odd because entries set in the GUI are visible when using Get-DfsnAccess... but not the other way around.

5) What is the actual difference between Remove and Revoke-DfsnAccess? I read the help files, but that doesn't really explain it to me. Also, why is there two methods for getting rid of access, but only 1 to grant and get?

Questions 1-3 seem like Microsoft oversights. How can I move past Question 4? That's critical to me. It it not feasible for me to use the gui on every folder/target to set explicit permissions.


Ian

Code Signing

$
0
0

I have an internal CA (2008 Standard, non-r2) with the code signing template available.  I generated a code signing certificate and signed a powershell script I've made.  When I try to run it on a domain member (that automatically trusts the CA), I still get the following prompt: "blah.ps1 is published by blah and is not trusted on your system.  Only run scripts from trusted publishers.  [V] Never run, [D] Do not run, [R] Run once [A] Always Run [?] Help"

I was assuming since it was signed with a certificate from the internal CA that it would automatically be trusted.  What am I missing here?

Thanks 

Extract All Distribution Lists where Group Type IS Security

$
0
0

Hi,

I am very new to powershell and I am trying to write a script to retrieve all the Distribution Lists in our Domain where the group type is security as we have changed our naming conventions and all these groups need to be renamed eventually.

How do I specify this?

Thanks

Sarah


how to run a powershell script as adminiatrator

$
0
0
when I right click the script I don't see an option to run as administrator. What is the easiest way to run a script as administrator.

Log or output LDAP-filtering

$
0
0

Hey, how can I output what I filter out with LDAP-filtering in the following? Do I have to use where-object to do that?

Get-QADGroupMember -SizeLimit 0 -Identity $Restgroup -Enabled -DontUseDefaultIncludedProperties -IncludedProperties Displayname,SamAccountName,Company,department,office,description -ldapfilter "(&(!(department=*test*))(!(title=*test*))(!(samaccountname=*test*))(!(company=*test*))(!(description=*test*))(!(Displayname=*fellesbruker*))(!(Description=*fellesbruker*))(!(name=*test*)))" | Sort Company)


I really dont want to use where-object, because of how slow it is..

Getting a list of files that fail to copy using a script

$
0
0

Hi there,

What I am trying to do is to make my powershell script to log wich files (including the full path) that failed to copy.

When I run the following command:

PS C:\> cp 'C:\source\*.*' c:\dest\ -ErrorAction SilentlyContinue

If there's a locked file, all what I get is this 

"cp : Access is denied
At line:1 char:1
+ cp 'C:\PS - Copy (12)\*.*' c:\testcopy -ErrorAction SilentlyContinue -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.CopyItemCommand

"

and I am wondering if there's a way to get exactly which file(s) that failed to copy.

Thanks i advance guys!

Regards,

How To Get Total Size - Folders

$
0
0

Hi,

I have a script that lists all .jpg in a folder but what i would like is to get the total size of those .jpg files if possible.

Get-Childitem c:\ -Recurse -filter *.jpg  |group Extension -NoElement | sort count -desc

Is this something easy?

Cheers

Help to determin if "Administrator" account is present

$
0
0

How can i find if the Administrator account exsits when using this method

$Server = "SRV01" $User = "Administrator" $Account = [ADSI]("WinNT://$server/$user,user") if($Account -contains "Administrator")`

{ Write-Host "$user account found on server $server" }

I've tried -contains but that doesn't work.


Viewing all 2562 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>