get windows key
PowerShell Script for complete folder upload
twice a week a folder is generated with pdf files inside, each folder is named with an ID number(Ejm ID523869) and the .pdf files named with a serial number(ejm 22081300340), each time a new forder with pdf files is added to the server local path, I need to manually upload that folder to an ftp site, and sometimes happend I forget to do this, so I'm looking for a powershell script that could automate this process to uploading each new folder added (with same name) to the ftp site, then log if upload process is successfully done and send an email notification, since new I'm new guy on powershell have a couple of days trying to mix some scripts to do this but not success yet. Hope somebody deal with something similar that could share his experience and script.
Thanks
Export list of Virtual Machines in Azure
Hi all,
I'm trying to find a way to export to CSV a list of all VM's against my Azure subscription.<o:p></o:p>
I seem to be going around in circles - some scripts look promising, some just fail miserably.<o:p></o:p>
Can anyone help me out?
I need to see:
Computer name
Resource group
Machine specs such as CPU, RAM, Disks mounted
Private IP address
Location
All machines in Azure are 2012 R2.
Cheers!
Hunt
Run Test-ADServiceAccount at remote machine
Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not
have the Active Directory Web Services running.
+ CategoryInfo : ResourceUnavailable: (:) [Get-ADServiceAccount], ADServerDownException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADServiceAccoun
t
+ PSComputerName : AlphaPLA02.englab.caradigm.com
by using below script.
$session = New-PSSession -ComputerName "AlphaPLA02.englab.caradigm.com" -Credential englab\amv3tst
Invoke-Command -Session $session -ScriptBlock `
{ `
$RSATInstalled = Get-WindowsFeature RSAT-AD-PowerShell ; `
if(!$RSATInstalled.Installed)
{
Add-WindowsFeature RSAT-AD-PowerShell ; `
} ;
};
Invoke-Command -Session $session -ScriptBlock { Test-ADServiceAccount "gMSACipPlatfor1$" ; }
How can I successfully run my remote script with administrator permissions?
I've been working on a small, redeployable .ps1 script that will be used to automate the clearing of the end user's print spooler and clearing of the printing queue, with more features in future implementation. Here's a snippet of some of the commands that require elevation.
In order to successfully run this script on end user's computers, I've created a Powershell credential object like so. (It doesn't matter if the administrator credentials are in clear text, since it is executed in the background over RMM).
However, when I try to run any command with the newly made variable like this,
I get some sort of complication, such as the PS window only returning the syntax of the command instead of actually running it. I'm relatively inexperienced in the Powershell automation; If someone could offer up a solution as to how to best integrate the newly made credential object into my script so that it will run with elevated permissions in its entirety, It'd be much appreciated. Thanks!!! |
How do i search a file for keywords then if a keyword or words are not found the get outputted to screen or a .txt in powershell
heres a small code i got from google and have been playing with . i got list of name in a txt file and i run it againt a htm
$key = Get-Content c:/users/jon/documents/t.htm
Get-Content c:/users/jon/documents/ll.txt -wait |
ForEach-Object {
foreach($word in $key){
if($_ -ne "Mia Albertson
")
{
write-host "Mia Albertson
"
exit
}
if($_ -match $word){
$_
}
}
}
WMI Logical FreeSpace and Size
I trying to run this command but free and size property is not showing anything.
Get-WmiObject -Class Win32_logicaldisk -Filter 'drivetype = 3' | Select @{N='Free';Ex={'{0:N1}' -f $_.freespace /1gb }},@{N='Size';Ex={'{0:N1}' -f $_.Size /1gb }}
How can I create registry key with slash in name?
I'm trying to create registry key as follows:
New-Item -Path 'HKCU:\Software\VB and VBA Program Settings\Liaison 98\SitaHost\PC/PCM' New-Item -Path "HKCU:\Software\VB and VBA Program Settings\Liaison 98\SitaHost\PC/PCM" New-Item -Path "HKCU:\Software\VB and VBA Program Settings\Liaison 98\SitaHost\PC`/PCM"
All 3 commands give error:
New-Item : The registry key at the specified path does not exist.
At line:1 char:1
+ New-Item -Path "HKCU:\Software\VB and VBA Program Settings\Liaison 98\SitaHost\P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (HKEY_CURRENT_US... 98\SitaHost\PC:String) [New-Item], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.NewItemCommand
As I understand it treats slash in PC/PCM as path seperator, and as PC key is missing it throws me an error. How can I escape slash in path so it will treat it as part of the name and not path seperator?
Unicode \u2019 error
Hi, I am running a cURL to return data. I am getting a txt file that I then translate in to CSV by using this function:
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load($xsl);
$xslt.Transform($xml, $output);
The problem is that I am returning characters other than English, and I am getting an error related to the unicode \u2019.
What would be the best approach to this. In Unix I would use xtslproc and recode html the text file, but somehow, I don't find any equivalence with Powershell.
Thanks
Delete files older than 24 hours
Hi guys,
with your help I created this script that delete from a folder all the files older than 14 days and keep just 1 for day from today to 14 days ago.
I need that ALL the files in the last 24 hours are not going to be deleted.
So, I need to have a folder with ALL the files in the last 24 hours, just 1 file from 24 hours ago to 14 days ago, and all the others deleted.
I attach you the script. Can you help me?
Thank you very much everyone
function remove-oldfiles{
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[ValidateScript({
if ((Test-Path "$_") -eq $true) { $true }
else { Throw "folder cannot be located" }
})]
[string]$FolderPath
)
dir -Path "$FolderPath" | where { $_.LastWriteTime -lt ((Get-Date).AddDays(-14)) } | Remove-Item -Force -Confirm:$false
$remaingfiles = dir -Path "$FolderPath" | select *, @{ n = 'DayofFile'; e = { $_.lastwritetime.toshortdatestring() } }
$groups = $remaingfiles | Group-Object dayoffile | where { $_.count -gt 1 }
if ($groups)
{
foreach ($group in $groups)
{
($group).group | sort lastwritetime -Descending | select -Skip 1 | Remove-Item -Force -Confirm:$false
}
}
}
Enable-ComputerRestore error msg "Include System Drive in the list of drives"
Hi,
I'm running Enable-ComputerRestore -drive "C:\" in WinPE8 but get this message "Include System Drive in the list of drives" in red ...
The C: drive is the Windows 8 system drive ...
If I run RecEnv.exe in PE8 it works fine after asking me to pick the OS (Windows 8.1). So powershell should work too, yes?
Do I have to run another command first to select "Windows 8.1" like i did using RecEnv.exe?
Harv
Create New Custom attribute in Active directory only with Powershell

Hi all
I have an Active Directory 2012, i want to be abel to create a powershell script, that can create a total new custom attribute in Active Directory. And then the script ,must be abel to enabel this new attribute to all OU in the domain, and to all the groups in AD.
Is there anyone´ho know how, to do this with only powershell commands?
I can find many guides by the GUI, but not only with Powershell.
I hope someone can help with this. Thanks...
CimException with Network Controller
I am trying to install Network controller on a 2016tp5 VM following this procedure: https://technet.microsoft.com/en-us/library/mt282165.aspx
I get an error while running the command
Install-NetworkController –Node $node –ClientAuthentication Kerberos -ClientSecurityGroup Contoso\NCRESTClients -ServerCertificate $cer
I get the following output:
Install-NetworkController : One or more errors occurred.
At line:1 char:1
+ Install-NetworkController -ClientAuthentication Kerberos -Node $node ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-NetworkController], CimException
+ FullyQualifiedErrorId : HRESULT 80131500,Microsoft.Windows.Networking.NetworkController.PowerShell.InstallNetworkContr
ollerCommand
Any ideas? I've tried to search the exception elsewhere but I can't seem to find what it means. What is that CimException?
Thanks!
**EDIT**
by running $error[5]|Format-List -force I get
Exception : Microsoft.Management.Infrastructure.CimException: One or more errors occurred.at Microsoft.Windows.Networking.NetworkController.PowerShell.ServerProviderWrapper.GetClusterConfi
guration(NetworkControllerCluster& clusterConfiguration)
TargetObject :
CategoryInfo : NotSpecified: (:) [Install-NetworkController], CimException
FullyQualifiedErrorId : HRESULT
80131500,Microsoft.Windows.Networking.NetworkController.PowerShell.InstallNetworkControllerCommand
ErrorDetails : One or more errors occurred.
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails :
Powershell Script to change DDGs to "All Recipient Types"
Hello -
Does anyone have a powershell script that can change a filter within a DDG to "All recipient types"? Please see attached image for what I am talking about.
Thanks
Facebook module question
when i get to the login step of this tutorial i sign in and a page asking for permissions is to come up but it dont why not?
http://newdelhipowershellusergroup.blogspot.ca/2012/08/facebook-module-for-powershell.html
i need the module to have permission so i can get friends list
Windows Net on xNix and iOS
Supported OSs with Net core.
- Red Hat Enterprise Linux 7.2
- Centos 7.1
- Debian 8.2+
- Ubuntu 14.04 (16.04 support is coming at RTM)
- Linux Mint 17+
- OS X 10.11
- Windows 7+ / Windows Server 2012 R2+
- Windows Nano Server TP5
\_(ツ)_/
Calendar Sharing for an AD Group
Hi,
In this post (https://social.technet.microsoft.com/Forums/scriptcenter/en-US/94bbcfaf-d963-46ff-9e6d-85ccde36d104/offce-365-assigning-calendar-permissions-via-security-groupsbulk-calendar-sharing?forum=winserverpowershell) there is a PowerShell command closest to a problem we have been having for some time now.
$GroupMembers = Get-DistributionGroupMember securityGroup1 foreach ($GroupMember in $GroupMembers) { Add-MailboxFolderPermission -Identity (""+ $GroupMember.Guid+ ":\Calendar") -User securityGroup1 -AccessRights Editor}
I wonder if you might be able to suggest an amended script to match the following requirements:
We have two security groups: AllStaff and AllStudents. We would like AllStaff group members to have Limited Details permission over AllStudent group members. (We don't want AllStudents to be able to see limited details of AllStaff).
Is this possible with an amendment to the script above. I wanted to make sure that I get the groups in the correct order so that I don't give permission the other way!
Many thanks in advance,
Michael
Debug Prompt not coming when Powershel breakpoint hit
Hi,
I have created a breakpoint as follows
Set-PSBreakpoint -Command get-process -Script C:\Temp\SP\AutoSPInstaller\AutoSPInstallerFunctions.ps1
or
Set-PSBreakpoint -Script C:\Temp\SP\AutoSPInstaller\AutoSPInstallerFunctions.ps1 -line 2132
Then I launch a batch file which internally calls PowerShell script AutoSPInstallerFunctions.ps1
C:\Temp\SP\AutoSPInstaller\AutoSPInstallerLaunch.bat
When the breakpoint hits DBG prompt does not show up it only shows me breakpoint hit it never provides me an option of step into, list ,step-over etc...
Any clue!!
PowerShell Find-DSCResource Error
When running Find-DSCResource or any other PowerShell Get cmdlts I get the following error.
"WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2/'."
I have looked online for other related issues, but have not had any joy.
Thanks
Craig
PowerShell Script to Catch Empty Query Result
Hello,
In the below script, when the results are written to the .csv file, it basically writes NO DATA text to every SQL server instance once withouttruly evaluating whether there are any data returned or not. I just want to make sure the output .csv file contains NO DATA for those SQL server instances where all the jobs were successful or no failure as shown in
the sql script. Can you please help where to correctly place the if statement in the PS script?
==========================================
##Save the below powershell script in folder "E:\PowerShellScripts\SQLServersBackupStatusFromMSDB.ps1"
$QueryPath= "E:\PowerShellScripts\SQLQueryNew1.sql"
$OutputFile = "E:\PowerShellScripts\BackupStatusQuery1_Output.csv"
$InputFile = "E:\PowerShellScripts\SQLServerList.txt"
$ExecuteQuery= Get-Content -path $QueryPath | out-string
#"Results -- > `r`n`r`n" > $OutputFile
FOREACH($server in GC $InputFile)
{
# if the SQL query returns a result set, then format the output
if($null -ne $sqlReturn)
{
$sqlReturn | Format-Table -autosize | Out-String -width 4096 >> $OutputFile
}
# if it does not, then output 'NO DATA'
else
{
'NO DATA' >> $OutputFile
}
$server
"---------------------------------------------------------------" >> $OutputFile
$server >> "E:\PowerShellScripts\BackupStatusQuery1_Output.csv"
"----------------------------------------------------------------" >> $OutputFile
invoke-sqlcmd -ServerInstance $server -query $ExecuteQuery -querytimeout 65534 | ft -autosize | out-string -width 4096 >> $OutputFile
Thanks.
Victor
Victor